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

Recent Posts

Multiply two numbers in Java using scanner| 5 different ways

Multiply two numbers in Java using scanner| 5 different ways In this article, we will…

3 months ago

5 different ways to Divide two numbers in Java using scanner

5 Different ways to Divide two numbers in Java using scanner In this article, we…

3 months ago

Learn 8 Ways to Subtract Two Numbers Using Methods in Java

Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…

4 months ago

10 ways to subtract two numbers in Java

10 ways to subtract two numbers in Java In this article, we will discuss the…

4 months ago

Java Code Examples – Multiply Two Numbers in 5 Easy Ways

Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…

4 months ago

How to Divide two numbers in Java| 5 different ways

How to Divide two numbers in Java| 5 different ways In this article, we will…

4 months ago

This website uses cookies.