Tuple

suggest change

Introduction

A tuple is an immutable sequence of values. Tuples are one of Python’s simplest and most common collection types, and can be created with the comma operator (value = 1, 2, 3).

Syntax

Remarks

Parentheses are required for the empty tuple. They are also required when a comma would otherwise separate arguments or other syntax, such as in a function call: f((1, 2)) passes one tuple, while f(1, 2) passes two arguments. They are optional in a plain assignment such as 1, 2, 3.

A tuple is a sequence of values. The values can be any type, and they are indexed by integers, so in that respect tuples are a lot like lists. The important difference is that tuples are immutable. A tuple can be used in a set or as a dict key only when every element is hashable.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents