您现在的位置是:课程教程文章

python如何访问元组中的元素

2023-12-18 17:25课程教程文章 人已围观

python访问元组中的元素的方法:我们可以使用下标索引来访问元组中的值。具体使用方法如:【tup1 = ('physics', 'chemistry', 1997, 2000);print tup1[0]】。

可以使用下标索引来访问元组中的值。

(推荐教程: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如何访问元组中的元素

上一篇:linux怎么执行python脚本

下一篇:没有了

站点信息

  • 文章统计篇文章