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 Program to Get Tuple Items