Introduction
Setup
Operators
variable
String
Number
Dtype & Comment
Lists
Tuples
Sets
Dictionaries
if else statement
For Loop
While Loop
iterator & iterable
Pre-Built functions
Function
Decorators
generators
Types of errors
Exceptions Handling
OOP
Regular expression
Create module
OS module
Date module
Random module
Math
Statistics module
Exercise 1
Exercise 2
Exercise 3
Learn Data Structure & Algorithm
Learn Numpy
Learn Pandas
Learn Matplotlib
Learn Seaborn
Learn Statistics
Learn Math
Learn MATLAB
Learn Machine learning
Learn Github
Learn OpenCV
Learn Deep Learning
Learn MySQL
Learn MongoDB
Learn Web scraping
Learn Excel
Learn Power BI
Learn Tableau
Learn Docker
Learn Hadoop
A tuple is used to store multiple collections of values in one variable. We can store too many values in a
tuple and perform a lot of work on it. We can store string, number, or both at the same time in a Tuple. We
can use capital letters and small letters in a Tuple. We can store duplicate values in a tuple. Once we create
a tuple, we can't change or update or remove the values of the tuple.
In list we can do change, update or remove values or data but in tuple after creating the list we can't remove
or delete or change any value. So it is a difference between list and tuple.
Index means the position number of each value which are stored in the tuple. In python, the index starts from 0. If there are 5 values in the tuple then its first index is 0 and the last index =(n-1) =(5-1)=4. Index numbers can be used in various ways. It's a very important thing. We can get tuple values using an index number. Suppose a tuple contains ten values or element. Now if we want to get first five element or if we want to get a particular value like number eight position value then we can do that by using index number.
We write tuple inside a first bracket.
So at first give the first brackets().
The string must be written inside a single or double quotation ('',") and for numbers no need to give a single
or double quote.
Give a comma between two values.
If we write numbers in the quotation then it will act as a string and we won't be able to perform mathematical
work on that tuple element. If we write numbers and letters or words together then we must use quotations.
Because if we write number and letters together then it no longer number it wil become a string. That's why we
have to give double or singe quotation if we write number and text together.
In the example we can see six different tuple. The process to creating the tuples is same but we put different data types of value in each tuple. In the first tuple we have all the string value, second tuple contain number as string, fourth contain number values, fifth and sixth contain both number and string value together.
To check that a value is present in the tuple or not "in" is used. If the value is present in the tuple then it will return true otherwise it will return false.
Example:In the example we are checking if the x tuple containing a as an element or not. Because the tuple containing a as an element.
Count() function shows that how many times a specified number appears in the tuple.
Example:In the example the tuple containing the value 4 three times. That's why we got the output 3.
If we pass a value that is present in a tuple then the index function will show the index number of that value. If that value appears more than one time then this function selects that value which it gets the first time.
Example:Look in the example 1 is in first and second position but the index function took the first 1 for work and return it index number 0.
By index number, you can get a single value or a set of single values from the tuple and this is called tuple slicing. Negative indexing means starting from the end of the tuple.
Example:1In the example, the tuple 2 index position value is c. So we get the output c. -2 means the selection will start from the end. Now if we go to the end of the tuple then we will see the last second value is d. So we got the output is d.
Example:2We can join multiple tuple and create one tuple.
Example:Here we joined two different tuples and created a single tuple