您的位置:

Python 程序:创建不同类型元组

写一个 Python 程序来创建不同类型的元组并打印出来。这个 Python 示例显示了整数、字符串、布尔、浮点、混合元组、元组内部的元组(嵌套元组)和列表元组的创建。

# Different Type Tuples

numericTuple = (10, 20, 30, 40, 50)
print("Numeric Tuple Items = ", numericTuple )

floatTuple = (10.25, 11.20, 19.37, 41.598)
print("Float Tuple Items = ", floatTuple )

stringTuple = ('orange', 'Mango', 'Grape', 'Apple')
print("String Tuple Items = ", stringTuple )

booleanTuple = (True, False, False, True, True)
print("Boolean Tuple Items = ", booleanTuple )

mixedTuple = ('orange', 25, 'Mango', 36.75, False, 10)
print("Mixed Tuple Items = ", mixedTuple )

nestedTuple = (10, 20, ('orange', 'Mango'), 30)
print("Nested Tuple Items = ", nestedTuple )

listTuple = (10, 20, ['Grape', 'Apple'], 70)
print("List Tuple Items = ", listTuple )