#列表,元组(),列表【】['second', ('minute', 'hour', 'day'), 'week', 'year','century'],错误
# time_list = ['second', ['minute', 'hour', 'day'], 'week', 'year','century']
time_list = ['second', ('minute', 'hour', 'day'), 'week', 'year','century']
print(time_list)
print(time_list[0])
time_list[1][0] = '6:00'
print(time_list)
报错:
C:\Users\???\AppData\Local\Programs\Python\Python37\python.exe "C:/Users/张腾森/Desktop/pyton实例/第一次代码-老师/python-bass-程序/second part/tuple.py"
Traceback (most recent call last):
['second', ('minute', 'hour', 'day'), 'week', 'year', 'century']
File "C:/Users/???/Desktop/pyton实例/第一次代码-老师/python-bass-程序/second part/tuple.py", line 10, in <module>
time_list[1][0] = '6:00'
second
TypeError: 'tuple' object does not support item assignment
只需要把
time_list = ['second', ('minute', 'hour', 'day'), 'week', 'year','century']
改成
time_list = ['second', ['minute', 'hour', 'day'], 'week', 'year','century']
原因:
1,元组用()
2.列表用【】
如果列表中用了(),改成【】,就好了