'str'对象没有属性'spilt'

问题描述 投票:0回答:1

string = input("输入3个随机字符串,以逗号分隔:")

如果 len(字符串)>8:
a=string.spilt(sep=",")
打印(一) 其他:
print("至少8个字符长")`

错误消息为 AttributeError: 'str' 对象没有属性 'spilt' 请指教我该怎么办。

python string attributeerror
1个回答
0
投票

您尝试使用的方法是

split
,而不是
spilt
。将
string.spilt(sep=",")
更改为
string.split(sep=",")
,它应该可以工作:

string = input("Enter 3 random strings, separated by commas:")

if len(string) > 8:
    a = string.split(sep=",")
    print(a)
else:
    print("at least 8 characters long")
© www.soinside.com 2019 - 2024. All rights reserved.