方法一:使用len()函数获取字符串的长度 len()函数是Python中一个内置函数,可以用于获取字符串、列表等对象的长度。下面是一个简单的示例代码:string = "Hello, world!"length = len(string)print("The length of the string is:", length)输出结果为:The length of the string is: 13 方法二:使用循环...
while 1: try: s = input().split(" ") ### reset if len(s) == 1 and s[0] != " "*len(s[0]): if s[0] == "reset"[:len(s[0])]: print("reset what") else: print("unknown command") ### 2 words elif len(s) == 2: if s[0] == "reset"[:len(s[0])]: print...
elif s[0] == "board"[:len(s[0])] and s[1] == "add"[:len(s[1])]: print("where to add") elif s[0] == "board"[:len(s[0])] and s[1] == "delete"[:len(s[1])]: print("no board at all") elif s[0] == "reboot"[:len(s[0])]: print("impossible") elif s...