用一個例子編寫一個 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)
原創文章,作者:VUN8C,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/129730.html