当尝试使用specific_string.casefold时,我会得到一个错误。
每当我试图将它连接到字符串上以进行打印(用于测试)时,我就会得到:
test = "test"
print("Lowercase: " + test.casefold)
"TypeError:只能将str (而不是"builtin_function_or_method")连接到str
每当我试图使用它作为if语句的条件时,它只是掩盖if语句,因为它不是真的。
test = "test"
if test.casefold == "test" :
print("test")
发布于 2020-06-14 15:41:38
您的语法应该是test.casefold()
而不是test.casefold
。通过使用test.casefold
,您将尝试将字符串与函数string.casefold
连接起来,而不是函数返回的内容。
https://stackoverflow.com/questions/62379380
复制相似问题