首页 > 编程知识 正文

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

时间:2023-11-24 15:33:42 阅读:308930 作者:IJQL

写一个 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 )

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。