Tuple Class 11 Python Notes covers Tuple Methods, Tuple Slicing, Traversing Tuple, Tuple Concatenation, Repetition and Membership operations with examples. This Tuple in Python Class 11 Computer Science Notes is prepared for all students to understand each concept easily and get highest marks. This Tuple in Python Class 11 Notes is written very concisely as per CBSE suggested Syllabus.
Tuple in Python
- Tuple is built in sequence data type in python.
- Stores multiple values
- Tuple item can be of different data types
- All the items are comma separated and enclosed in parenthesis ‘()’.
- Individual item in a Tuple can be accessed using index which begins from 0.
- In case of single item present in tuple, it should also be followed by a comma.
- A sequence without parenthesis is treated as tuple by default.
Accessing elements in a Tuple
- Individual item in a Tuple can be accessed using indexes.
- Indexes are unique numbers assigned to each item in a Tuple to identify them
- Index always begins from 0 and written in square brackets “”.
Tuple is Immutable
- Yes Tuple is Immutable.
- Content of the Tuple cannot be changed after it has been created.
Tuple supports following operations:
- Concatenation refers to joining two Tuple.
- Plus (‘+’) is used as concatenation operator.
- Concatenation operator can also be used for extending an existing tuple.
- Repetition as it name implies used to repeat elements of a Tuple at specified no of times.
- Asterisk (‘*’) is used as repetition operator.
- Membership operation refers to checking an item exists in Tuple or not.
- Python uses ‘in’ and ‘not in’ as membership operator.
- ‘in’ returns true if the item specified present in the Tuple.
- ‘not in’ returns true if the item specified present in the Tuple.
- Extracting a subset of items from given Tuple is called slicing
- Subset occurred after slicing contains contiguous items.
- Slicing is done using index range like Tuple[start_index : end_index : step_value]
- End index is always excluded in resultant subset of Tuple.
- Negative index can also be used for slicing.
Traversing a Tuple
- Traversing a Tuple refers to accessing each item a given Tuple sequentially.
- for or while loop can be used for traversing a Tuple.
Tuple Methods and Built in Functions
One Tuple appears as an element inside another Tuple.
Tuple Assignment allows elements of tuple on the left side of assignment operator to be assigned respective values from a tuple on the right side.