This document introduces tuples in Python. Tuples are used to store multiple items in a single variable. They are ordered, unchangeable collections that can contain duplicate values. Tuples are defined using round brackets and can contain different data types. Values in a tuple can be accessed using indexes and sliced, though tuples themselves are unchangeable without first converting to a list. Loops can be used to iterate through tuple elements.
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
19 views
Python - Tuple
This document introduces tuples in Python. Tuples are used to store multiple items in a single variable. They are ordered, unchangeable collections that can contain duplicate values. Tuples are defined using round brackets and can contain different data types. Values in a tuple can be accessed using indexes and sliced, though tuples themselves are unchangeable without first converting to a list. Loops can be used to iterate through tuple elements.
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10
Python Programming Language
TUPLE Learning Outcome
To introduce Tuple data type in Python
programming language. To be able to code utilising the Tuple. Introduction
Used to keep multiple items in a single
variable. It is collection of ordered and unchangeable items. Can include duplicate values. Written with round brackets. It is indexed with first item as index (0), second item with index (1) and so on… Sample
NEW: -1 is referring to the last item, -2 is second last item. Access Tuple 2
myFruitsItems = (“Rambutan”, “Mangosteen”,
“Langsat”, “Mango”, “Ciku”, “Banana”) print(myFruitsItems[2:5]) NOTE: start from index 2 BUT not included index 5 Change Tuple Value Please remember Tuple is unchangeable, OR add new item OR remove an item once it was created.
BUT, we can convert it to list and reconvert it to Tuple.