gpt4 book ai didi

python - 如何使用len且不区分大小写?

转载 作者:行者123 更新时间:2023-11-30 23:37:35 25 4
gpt4 key购买 nike

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 <= ba.issubset(b) 的简写.

关于python - 如何使用len且不区分大小写?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15399984/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com