Python 程序:获取元组项
后浪云Python教程:
用一个例子编写一个 Python 程序来获取或访问元组项。在 Python 中,我们可以使用正负索引位置来访问元组项。在这个 Python 示例中,我们使用正索引位置和负索引位置来获取或检索或访问元组项。
# Get Tuple Items
intTuple = (10, 20, 30, 40, 50, 60, 70, 80, 90)
print("Tuple Items = ", intTuple)
fourthItem = intTuple[3]
print("Tuple Fourth Item = ", fourthItem)
firstItem = intTuple[0]
print("Tuple First Item = ", firstItem)
fourthItemfromLast = intTuple[-4]
print("Tuple Fourth Item from Last = ", fourthItemfromLast)
sixthItemfromLast = intTuple[-6]
print("Tuple Sixth Item from Last = ", sixthItemfromLast)
版权声明:
作者:后浪云
链接:https://www.idc.net/help/184235/
文章版权归作者所有,未经允许请勿转载。
THE END