
可以使用下标索引来访问元组中的值。
(推荐教程:Python入门教程)
代码如下:
#!/usr/bin/python
tup1 = ('physics', 'chemistry', 1997, 2000);
tup2 = (1, 2, 3, 4, 5, 6, 7 );
print "tup1[0]: ", tup1[0]
print "tup2[1:5]: ", tup2[1:5]输出结果:
#tup1[0]: physics #tup2[1:5]: [2, 3, 4, 5]

可以使用下标索引来访问元组中的值。
(推荐教程:Python入门教程)
代码如下:
#!/usr/bin/python
tup1 = ('physics', 'chemistry', 1997, 2000);
tup2 = (1, 2, 3, 4, 5, 6, 7 );
print "tup1[0]: ", tup1[0]
print "tup2[1:5]: ", tup2[1:5]输出结果:
#tup1[0]: physics #tup2[1:5]: [2, 3, 4, 5]
© 2021 Python学习网 苏ICP备16018502号-40