Table of Contents
Tuple in python language with example
In this tutorial, we will discuss the concept of Tuple in python programming language
In python language, tuple is similar to a list with some difference. the differents between both are we can not changed the elements of tuple once after is is assigned. but list elenment can be changed
Creating tuple
When we create a tuple in Python, we can be place all elements inside the paranthisis and seperated by commas.
A tuple can be any type of data type(int, float, list etc) and any nyumber of elements
Accessing element of tuple
1. print every element from tuple
Output
Zeroth index element mathan
first index element mohan
second index element seelan
third index element sutha
forthh index element mugunthan
fifth index element neela
2. print element continuosly with out ‘comma’ from tuple
Output
mathan mohan seelan sutha mugunthan neela
3. print any element using array index
1, dislay zero index element given tuple
Output
Zero index element : Maths
2. dislay zero in to zero index element given tuple
Output
Zero in to Zero index element : M
Access element from one tuple through another tuple
1. print Element same tuple of subject
output
Zero index Element: English
Output
First index Element: student
Access element from one tuple through another tuple
below Example shown as access element from subject tuple through school tuple
Output
Zero index Element: (‘Maths’, ‘Science’, ‘English’, ‘Tamil’, ‘Music’, ‘Arts’)
Zero in to Zero index Element: Maths
Zero into Zero into Zero index Element: M
Related post
Data type in Python List in Python