Python tuple() 函數

實例

創建包含水果名的元組:

x = tuple(('apple', 'banana', 'cherry'))

運行實例

定義和用法

tuple() 函數創建元組對象。

注釋:您不能更改或刪除元組中的項目。

請在 “Python 元組” 一章中學習有關集合的更多知識。

語法

tuple(iterable)

參數值

參數 描述
iterable 必需。序列,集合或可迭代對象。