标签:err 类型 次数 切片 基本数据类型 item 相互 bsp append
tuple_test=(10,20,30,["list","Jim","Mary",(123,"xuhongmei")],True,33)
for item in tuple_test:
print(item)
"""返回的结果
10
20
30
[‘list‘, ‘Jim‘, ‘Mary‘, (123, ‘xuhongmei‘)]
True
33
"""
tuple_test=(10,20,30,["list","Jim","Mary",(123,"xuhongmei")],True,33)
tuple_test[3][3]="yx"
print(tuple_test)
"""返回的结果
(10, 20, 30, [‘list‘, ‘Jim‘, ‘Mary‘, ‘yx‘], True, 33)
"""
tuple_test=(10,20,30,["list","Jim","Mary",(123,"xuhongmei")],True,33)
tuple_test[3].append("yuxianming")
print(tuple_test)
"""返回的结果
(10, 20, 30, [‘list‘, ‘Jim‘, ‘Mary‘, (123, ‘xuhongmei‘), ‘yuxianming‘], True, 33)
"""
del tuple_test[0]
print(tuple_test)
"""返回结果报错
NameError: name ‘tuple_test‘ is not defined
"""
tuple_test=(10,20,30,["list","Jim","Mary",(123,"xuhongmei")],True,33)
v=tuple_test[3][3]
print(v)
"""返回的结果
(123, ‘xuhongmei‘)
"""
tuple_test=(10,20,30,["list","Jim","Mary",(123,"xuhongmei")],True,33)
v1=tuple_test[1:3]
print(v1)
"""返回的结果
(20, 30)
"""
tuple_test=(10,20,30,["list","Jim","Mary",(123,"xuhongmei")],True,33)
v2=list(tuple_test)
print(v2)
"""返回的结果
[10, 20, 30, [‘list‘, ‘Jim‘, ‘Mary‘, (123, ‘xuhongmei‘)], True, 33]
"""
str_test=""
for item in tuple_test:
item=str(item)
str_test=str_test+item
print(str_test)
"""返回的结果
102030[‘list‘, ‘Jim‘, ‘Mary‘, (123, ‘xuhongmei‘)]True33
"""
tuple_test=(10,20,30,["list","Jim","Mary",(123,"xuhongmei")],True,33,33,20,10)
v3=tuple_test.count(10)
print(v3)
"""返回的结果
2
"""
tuple_test=(10,20,30,["list","Jim","Mary",(123,"xuhongmei")],True,10,33,20,10)
v4=tuple_test.index(10,2,8) 从下标2位置开始一直到8,第1个出现"10"的索引位置是5
print(v4)
"""返回结果
5
"""
标签:err 类型 次数 切片 基本数据类型 item 相互 bsp append
原文地址:https://www.cnblogs.com/yuxianming/p/9446460.html