|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
1
locations=('jiuzaigou,chongqing,suzhou,newYork,zhaoyingcheng')
locations.sort()
print(locations)
AttributeError Traceback (most recent call last)
<ipython-input-4-77d28d7b3ac1> in <module>
1 locations=('jiuzaigou,chongqing,suzhou,newYork,zhaoyingcheng')
----> 2 locations.sort()
3 print(locations)
AttributeError: 'str' object has no attribute 'sort'
2
locations=['jiuzaigou','chongqing','suzhou','newYork','zhaoyingcheng']
locations.sort()
print(locations)
['chongqing', 'jiuzaigou', 'newYork', 'suzhou', 'zhaoyingcheng']
为何上下不同?举个例子:
(‘1,2’)和【‘1,2’】有什么不一样?
求解答。
本帖最后由 sunrise085 于 2020-9-21 09:27 编辑
你写的第一个只有两端有引号,locations=('jiuzaigou,chongqing,suzhou,newYork,zhaoyingcheng')
中间没有任何引号,这是个字符串,字符串不能排序
你写的第二个,locations=['jiuzaigou','chongqing','suzhou','newYork','zhaoyingcheng']每个逗号之间都有引号,是一个多元素列表,列表可排序
所以根本不是小括号和中括号的问题
|
|