在 Python 中访问元组的值
pythonserver side programmingprogramming更新于 2025/4/5 9:16:17
要访问元组中的值,请使用方括号以及索引进行切片以获取该索引处可用的值。
示例
#!/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 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

