用一个例子编写一个 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)
标签: python基础