Tuple in python language with example

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       

Dictionary in Python

Set Data type in Python

 

Karmehavannan

Share
Published by
Karmehavannan

Recent Posts

Subtract two numbers using method overriding

Subtract two numbers using method overriding   Program 1

3 months ago

PHP Star triangle Pattern program

PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…

3 months ago

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

1 year ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

1 year ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

1 year ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

1 year ago

This website uses cookies.