标签:IV 支持 英文 索引 count result 报错 for循环 开始
test = (30, 5, 12, 23, 18, 45) result = test[2] print(result)
输出:
12
test = (30, 5, 12, 23, 18, 45) result = test[2:-1] print(result)
输出:
(12, 23, 18)通过for循环遍历元组中元素,eg:
test = (30, 5, 12,) for result in test: print(result)
输出:
30 5 12
test = (30, 5, 12, 5, 56, 5,) result = test.index(5) print(result)
输出:
1
test = (30, 5, 12, 5, 56, 5,)
result = test.count(5)
print(result)
输出:
3
test1 = (30) test2 = (30,) print(type(test1), type(test2), sep="\n")
输出:
<class ‘int‘> <class ‘tuple‘>
标签:IV 支持 英文 索引 count result 报错 for循环 开始
原文地址:https://www.cnblogs.com/xieliuxiang/p/9235912.html