Day-9 || Data Collection- Tuples ||

Python

Day-9 || Data Collection- Tuples ||

Hello World!!!!!!!!! Welcome Back to my World. Its JITHU, your friend who gonna help you to play with Python. Let’s get ready for getting dirty your hands. Today we will dive into Day-9 that is TUPLE. Yeap this is another Data-Structure as I promised you that I will tell u one DataStructure a day, let’s Begin with a Question What is TUPLE?

 

 

What is Tuple?

Let me answer this in a simple way, Tuples are the immutable Lists and it has Parenthesis ().

Creation of Tuple:

Empty Tuple:

Creating a Tuple without any Element.

Numbered Tuple:

A Tuple that containing only integers is called Numbered Tuple.

String Tuple:

A Tuple that contains only Strings is called String Tuple.

Mixed Tuple:

A Tuple that contains both the integers and String type of data is called Mixed Tuple.

Nested Tuple:

A Tuple that contains integers, string, and Other lists are called as nested Tuple.

 

Tuples can be created in another 2 ways…

Packing Tuple:

Creating a Tuple without Parenthesis is called Packing Tuple

Unpacking Tuple:

Creating a with parenthesis and getting the tuple name by accessing the tuple items.

By Default, the Single Character in the Tuple may be an “int” Or “Str”, But it can be overridden by adding a Comma[,] to it.

Tuple Methods:

Python has 2 Methods. They are 1] count()   2] index()

1] count():

This method is used for count the items that the user mentioned in the parenthesis. SYNTAX: tuple.count(x)

index():

This method is used to get the index value of the first item in the tuple SYNTAX: tuple.index(x)

Hey, Tuples are immutable so if want to delete Or add elements what to do know?

Adding  and Deleting Elements in Tuple:

Built-in functions in Tuple:

all():

This method returns true when all items are iterable, or false.

TRUE: when all Elements in the iterable are true.

FALSE: when all the Elements in the iterable are false.

any():

This method returns true when any element in the iterable is true, or false.

Bye, Wizards Let’s meet later with the Topic called SETS……….

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.