标签:use 列表 sign 引号 ack module most item err
元组a=(1,2,3,4)
print(a)
print(a[1:4])
# a[1]="4"
# print(a) //报错
(1, 2, 3, 4)
(2, 3, 4)
Traceback (most recent call last):
File "C:/Users/xiaojiaxin/PycharmProjects/fullstack1/week1/day3/tuple1.py", line 12, in <module>
a[1]="4"
TypeError: ‘tuple‘ object does not support item assignment
Enumrate函数:
b=("a","b","c")
for i in b:
print(i)
for i in enumerate(b): //把索引值加进去
print(i)
for i in enumerate(b,1): #每个引索号+1
print(i)
for i,v in enumerate(b,1):
print(i,">>>>",v)
for a,c in enumerate(b,2): #每个索引号+2
print(a,"---",c)
a
b
c
(0, ‘a‘)
(1, ‘b‘)
(2, ‘c‘)
(1, ‘a‘)
(2, ‘b‘)
(3, ‘c‘)
1 >>>> a
2 >>>> b
3 >>>> c
2 --- a
3 --- b
4 --- c
标签:use 列表 sign 引号 ack module most item err
原文地址:http://blog.51cto.com/10777193/2069808