stop = False
text_count = 0
while stop is False:
int_string = input("What is the initial string? ")
int_string = int_string.lower()
for a in int_string:
for a in b:
text_count += 1
if text_count < 3:
print("Error: string must have at least 3 characters.")
elif len(int_string) != 'X' or len(int_string) != 'x' or len(int_string) != '_':
print("Error: string must contain only X and _.")
该字符串的长度必须至少为 3 个字符,并且只能包含字符“X”、“x”或“_”(下划线) 也不区分大小写
最佳答案
您可以将其转换为 set
对象并将其与您允许的字符集进行比较:
while not stop:
int_string = input("What is the initial string? ").lower()
if len(int_string) < 3:
print("Error: string must have at least 3 characters.")
elif set(int_string) <= {'x', '_'}:
print("Error: string must contain only X and _.")
a <= b
是 a.issubset(b)
的简写.
关于python - 如何使用len且不区分大小写?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15399984/