SlideShare a Scribd company logo
TUPLE IN PYTHON
COMPUTER SCIENCE(083)
XII
What is tuple?:
A tuple is a collection of values or an ordered sequence of values
similar to list.
Elements of a tuple enclosed in a parenthesis ( ), separated by
commas (,) .
Syntax:
tuple_name= (value1, value2,……..,valueN)
Example:
tup = (10, 20, 30, 40, 50 )
HOW TO CREATE AND INITIALIZE TUPLE
Method 1: If tuple is declare empty.
tup1=( )
Method 2: Initialize tuple with value:
If we want to store the numbers in a tuple.
tup2= (1, 2, 30, 4, 15)
If we want to store the words or string in a tuple.
tup3= (‘MON’, ‘TUE’, ’WED’, ’THU’)
HOW TO CREATE AND INITIALIZE TUPLE
Example: If we want to store the characters in a tuple.
tup4= (‘A’,’E’,’I’,’O’,’U’)
Example: If we want to store the mixed information in a tuple.
tup4= (“Kapil”, 13,”Class-IX”, 40)
TO DISPLAY THE TUPLE
Example:
tup2= (10, 20, 30, 40, 50)
print(tup2)
----------------Output-------------
(10, 20, 30, 40, 50)
Example:
tup= (“Mango”, “Apple”,”Grapes”,”Oranges”)
print(tup)
----------------Output-------------
(‘Mango’, ‘Apple’, ’Grapes’, ’Oranges’)
HOW TO CREATE AND INITIALIZE THE TUPLE
USING TUPLE() CONSTRUCTOR
Syntax:
tuple_name=tuple(sequence or string)
Example:
tup1=tuple()
Print(tup1)
----------output----------
( )
tup4= tuple((‘A’,’E’,’I’,’O’,’U’))
print(tup4)
If we want to store the characters in a list
tup4= tuple(“AEIOU”)
print(tup4)
---------Output----------
(‘A’, ‘E’,’I’,’O’,’U’)
HOW TO CREATE AND INITIALIZE THE TUPLE
USING TUPLE() CONSTRUCTOR
Example:
If we want to store the mixed information in a list.
tup4= tuple((“Kapil”, 13,”Class-IX”, 40))
print(tup4)
----------------Output-------------
(‘Kapil’, 13,’Class-IX’, 40)
Example: If we want to store the numbers in a tuple.
tup2=tuple((10, 20, 30, 40, 50))
print(tup2) ----------------Output-------------
(10, 20, 30, 40, 50)
HOW USER ENTER THE VALUES IN A TUPLE
AT RUN TIME.
We can use eval( ) method, which identifies the data type
and evaluate them automatically.
Example:
no=eval(input(“Enter the no:”))
print(no)
-------Input-----------
Enter the no: 1,2,3,4,5,6,7,8,9
-----------Output-------------
(1,2,3,4,5,6,7,8,9)
Example:
tup1=()
x=1
while x<=5:
no=int(input(“Enter the no:”))
tup1=tup1+(no,)
x=x+1
print(tup1)
====OUTPUT=====
Enter the no:10
Enter the no:20
Enter the no:30
Enter the no:40
Enter the no:50
(10, 20, 30, 40, 50)
Accessing Tuple Elements
Example: Let’s store no’s in a tuple
no=(10,20,30,40,50,60,70,80)
0 1 2 3 4 5 6 7
10 20 30 40 50 60 70 80
-8 -7 -6 -5 -4 -3 -2 -1
Positive index
Negative index
Now To access these tuple let us discuss
operations of tuple
Tuple operations
Indexing Slicing Repetition Concatenation Membership
Testing
Indexing
Indexing specify the position of elements in a tuple or sequence and
help us to access the value from the sequence separately.
For Example:
if we want to access the number 60 from a tuple given below using
positive index number and 20 using negative number
0 1 2 3 4 5 6 7
10 20 30 40 50 60 70 80
-8 -7 -6 -5 -4 -3 -2 -1
Positive index
Negative index
Indexing 0 1 2 3 4 5 6 7
10 20 30 40 50 60 70 80
-8 -7 -6 -5 -4 -3 -2 -1
no=(10,20,30,40,50,60,70,80)
print(no[4])
--------output--------
50
No=(10,20,30,40,50,60,70,80)
print(no[-6])
--------output-------------
30
Slicing
Slicing is an operation in which you can slice a particular range
from a sequence.
Syntax: tupname [start : stop : step]
Where, start is the starting point
Stop is the stopping point
Step is the step size—also known as stride, and is
optional. Its default value is 1
Slicing Now let Us take one Example:
print ( no [-3 : ] ) 60, 70, 80
print ( no [ 1 : 4 ] ) 20,30,40
Items from 1 to 3
0 1 2 3 4 5 6 7
10 20 30 40 50 60 70 80
-8 -7 -6 -5 -4 -3 -2 -1
no=(10,20,30,40,50,60,70,80)
Concatenation
It is a process in which tuple can be combine together with the help
of ‘+’ operator.
Example:
t1=(10,20,30)
t2=(1,2,3)
In this t1 we add t2 and original t1 overwritet1=t1+t2
------------output--------------
(10, 20, 30, 1, 2, 3)
print(t1)
Repetition
Multiply ( * asterisk) operator replicates the tuple for specified
number of times.
Example: tup1=(1,2)
print(tup1*3)
------------output--------------
(1, 2, 1, 2,1,2)
It check whether a particular element or item is a member of that
sequence or tuple or not.
There are two operator:
1. in operator 2. not in operator
Membership Testing:
in operator:
It returns true if element appears
in the tuple, otherwise returns
false.
Example:
tup1=(10,20,30,40)
print(30 in tup1)
----------output-----------
True
Note: it will give True if
value not exists inside
the tuple
not in operator:
It returns true if element not appears in the
tuple, otherwise returns false.
Example:
tup1=(10,20,30,40)
print(50 not in tup1)
----------output-----------
True
Tuple functions
len()
count() It count number of times a specified value occurs in a tuple
It returns the length of the tuple means count total number of elements
in a tuple.
tup=(1,2,3,4,5,6,7,8,9)
print(len(tup))
-----Output------
9
tup=(1,2,3,2,4,5,6,2,7,2,8)
print(tup.count(2))
--------OUTPUT-------
4
any()
index() Searches the tuple for a specified value and returns the position of
where it was found
It return True, if a tuple is having at least one item.If the tuple is
empty, it will return False.
Tuple functions
tup=(1,2,3,2,4,5,6,2,7,2,8)
print(tup.index(2))
-----Output------
1
tup=(1,2,3)
print(any(tup))
-----Output------
True
tup=()
print(any(tup))
-----Output------
False
If there are
elements
inside it
display
true
If the tuple is empty
it display False
min() and max()
sorted() It is used to sort the elements in a tuple.
tup=(-10,25,-5,1,6,19,7)
print(sorted(tup))
-----Output------
(-10, -5, 1, 6, 7, 19, 25)
tup=(10,25,5,1,6,19,7)
print("Max:",max(tup)," Min:",min(tup))
Max: 25 Min: 1
Traversing Tuple or how to display the tuple
elements using loops
tup=(1,2,3,4,5,6,7,8,9)
for x in range(0,len(tup)):
print(tup[x])
-----Output------
1
2
3
4
5
6
7
8
9
tup=(1,2,3,4,5,6,7,8,9)
x=0
while x<len(tup):
print(tup[x])
x=x+1

More Related Content

What's hot (20)

PPT
Synchronization.37
myrajendra
 
PPTX
Java String
SATYAM SHRIVASTAV
 
PPTX
Data Structures in Python
Devashish Kumar
 
PPTX
C# classes objects
Dr.Neeraj Kumar Pandey
 
PPTX
File Handling Python
Akhil Kaushik
 
PPTX
Python Functions
Mohammed Sikander
 
PPTX
Python- Regular expression
Megha V
 
PPTX
Introduction to Java Strings, By Kavita Ganesan
Kavita Ganesan
 
PPTX
String, string builder, string buffer
SSN College of Engineering, Kalavakkam
 
PDF
Python : Regular expressions
Emertxe Information Technologies Pvt Ltd
 
PPS
String and string buffer
kamal kotecha
 
PPTX
Python strings presentation
VedaGayathri1
 
PPT
Sql DML
Vikas Gupta
 
PDF
Strings in java
Kuppusamy P
 
PPTX
SQLite database in android
Gourav Kumar Saini
 
PPTX
Dynamic memory allocation
Viji B
 
PPT
SQLITE Android
Sourabh Sahu
 
ODP
OOP java
xball977
 
PPTX
Static Members-Java.pptx
ADDAGIRIVENKATARAVIC
 
Synchronization.37
myrajendra
 
Java String
SATYAM SHRIVASTAV
 
Data Structures in Python
Devashish Kumar
 
C# classes objects
Dr.Neeraj Kumar Pandey
 
File Handling Python
Akhil Kaushik
 
Python Functions
Mohammed Sikander
 
Python- Regular expression
Megha V
 
Introduction to Java Strings, By Kavita Ganesan
Kavita Ganesan
 
String, string builder, string buffer
SSN College of Engineering, Kalavakkam
 
Python : Regular expressions
Emertxe Information Technologies Pvt Ltd
 
String and string buffer
kamal kotecha
 
Python strings presentation
VedaGayathri1
 
Sql DML
Vikas Gupta
 
Strings in java
Kuppusamy P
 
SQLite database in android
Gourav Kumar Saini
 
Dynamic memory allocation
Viji B
 
SQLITE Android
Sourabh Sahu
 
OOP java
xball977
 
Static Members-Java.pptx
ADDAGIRIVENKATARAVIC
 

Similar to Tuple in python (20)

PDF
Tuples in Python
DPS Ranipur Haridwar UK
 
PPTX
Tuplemathspresentationonteupleshhhh.pptx
DeepakThakur612948
 
PPTX
PRESENTATION ON TUPLES.pptx
rohan899711
 
PPTX
Tuples class 11 notes- important notes for tuple lesson
nikkitas041409
 
PDF
Python Is Very most Important for Your Life Time.
SravaniSravani53
 
PDF
Tuple in Python class documnet pritened.
SravaniSravani53
 
PPTX
Unit-4 Basic Concepts of Tuple in Python .pptx
SwapnaliGawali5
 
PPTX
Python programming UNIT III-Part-2.0.pptx
Ponnusamy S Pichaimuthu
 
PDF
Tuple Operation and Tuple Assignment in Python.pdf
THIRUGAMING1
 
PPTX
Tuples in Python Object Oriented Programming.pptx
MuhammadZuhairArfeen
 
PDF
Python Tuple.pdf
T PRIYA
 
PDF
Python-Tuples
Krishna Nanda
 
PPTX
Tuple.py
nuripatidar
 
PDF
updated_tuple_in_python.pdf
Koteswari Kasireddy
 
PPTX
58. Tuples python ppt that will help you understand concept of tuples
SyedFahad39584
 
PPTX
Lists_tuples.pptx
M Vishnuvardhan Reddy
 
PDF
014 TUPLES.pdf
amman23
 
PPT
Programming in Python Lists and its methods .ppt
Dr. Jasmine Beulah Gnanadurai
 
PPTX
Chapter 13 Tuples.pptx
vinnisart
 
Tuples in Python
DPS Ranipur Haridwar UK
 
Tuplemathspresentationonteupleshhhh.pptx
DeepakThakur612948
 
PRESENTATION ON TUPLES.pptx
rohan899711
 
Tuples class 11 notes- important notes for tuple lesson
nikkitas041409
 
Python Is Very most Important for Your Life Time.
SravaniSravani53
 
Tuple in Python class documnet pritened.
SravaniSravani53
 
Unit-4 Basic Concepts of Tuple in Python .pptx
SwapnaliGawali5
 
Python programming UNIT III-Part-2.0.pptx
Ponnusamy S Pichaimuthu
 
Tuple Operation and Tuple Assignment in Python.pdf
THIRUGAMING1
 
Tuples in Python Object Oriented Programming.pptx
MuhammadZuhairArfeen
 
Python Tuple.pdf
T PRIYA
 
Python-Tuples
Krishna Nanda
 
Tuple.py
nuripatidar
 
updated_tuple_in_python.pdf
Koteswari Kasireddy
 
58. Tuples python ppt that will help you understand concept of tuples
SyedFahad39584
 
Lists_tuples.pptx
M Vishnuvardhan Reddy
 
014 TUPLES.pdf
amman23
 
Programming in Python Lists and its methods .ppt
Dr. Jasmine Beulah Gnanadurai
 
Chapter 13 Tuples.pptx
vinnisart
 
Ad

More from vikram mahendra (20)

PPTX
Communication skill
vikram mahendra
 
PDF
Python Project On Cosmetic Shop system
vikram mahendra
 
PDF
Python Project on Computer Shop
vikram mahendra
 
PDF
PYTHON PROJECT ON CARSHOP SYSTEM
vikram mahendra
 
PDF
BOOK SHOP SYSTEM Project in Python
vikram mahendra
 
PPTX
FLOW OF CONTROL-NESTED IFS IN PYTHON
vikram mahendra
 
PPTX
FLOWOFCONTROL-IF..ELSE PYTHON
vikram mahendra
 
PPTX
FLOW OF CONTROL-INTRO PYTHON
vikram mahendra
 
PPTX
OPERATOR IN PYTHON-PART1
vikram mahendra
 
PPTX
OPERATOR IN PYTHON-PART2
vikram mahendra
 
PPTX
USE OF PRINT IN PYTHON PART 2
vikram mahendra
 
PPTX
DATA TYPE IN PYTHON
vikram mahendra
 
PPTX
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
vikram mahendra
 
PPTX
USER DEFINE FUNCTIONS IN PYTHON
vikram mahendra
 
PPTX
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
vikram mahendra
 
PPTX
INTRODUCTION TO FUNCTIONS IN PYTHON
vikram mahendra
 
PPTX
Python Introduction
vikram mahendra
 
PPTX
GREEN SKILL[PART-2]
vikram mahendra
 
PPTX
GREEN SKILLS[PART-1]
vikram mahendra
 
PPTX
Dictionary in python
vikram mahendra
 
Communication skill
vikram mahendra
 
Python Project On Cosmetic Shop system
vikram mahendra
 
Python Project on Computer Shop
vikram mahendra
 
PYTHON PROJECT ON CARSHOP SYSTEM
vikram mahendra
 
BOOK SHOP SYSTEM Project in Python
vikram mahendra
 
FLOW OF CONTROL-NESTED IFS IN PYTHON
vikram mahendra
 
FLOWOFCONTROL-IF..ELSE PYTHON
vikram mahendra
 
FLOW OF CONTROL-INTRO PYTHON
vikram mahendra
 
OPERATOR IN PYTHON-PART1
vikram mahendra
 
OPERATOR IN PYTHON-PART2
vikram mahendra
 
USE OF PRINT IN PYTHON PART 2
vikram mahendra
 
DATA TYPE IN PYTHON
vikram mahendra
 
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
vikram mahendra
 
USER DEFINE FUNCTIONS IN PYTHON
vikram mahendra
 
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
vikram mahendra
 
INTRODUCTION TO FUNCTIONS IN PYTHON
vikram mahendra
 
Python Introduction
vikram mahendra
 
GREEN SKILL[PART-2]
vikram mahendra
 
GREEN SKILLS[PART-1]
vikram mahendra
 
Dictionary in python
vikram mahendra
 
Ad

Recently uploaded (20)

PDF
My Thoughts On Q&A- A Novel By Vikas Swarup
Niharika
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
I INCLUDED THIS TOPIC IS INTELLIGENCE DEFINITION, MEANING, INDIVIDUAL DIFFERE...
parmarjuli1412
 
PPTX
Applications of matrices In Real Life_20250724_091307_0000.pptx
gehlotkrish03
 
PPTX
Cybersecurity: How to Protect your Digital World from Hackers
vaidikpanda4
 
PPTX
Rules and Regulations of Madhya Pradesh Library Part-I
SantoshKumarKori2
 
PDF
Tips for Writing the Research Title with Examples
Thelma Villaflores
 
PPTX
THE JEHOVAH’S WITNESSES’ ENCRYPTED SATANIC CULT
Claude LaCombe
 
PPTX
Virus sequence retrieval from NCBI database
yamunaK13
 
PPTX
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
PPT
DRUGS USED IN THERAPY OF SHOCK, Shock Therapy, Treatment or management of shock
Rajshri Ghogare
 
PPTX
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
PDF
Stepwise procedure (Manually Submitted & Un Attended) Medical Devices Cases
MUHAMMAD SOHAIL
 
PPTX
Applied-Statistics-1.pptx hardiba zalaaa
hardizala899
 
PDF
EXCRETION-STRUCTURE OF NEPHRON,URINE FORMATION
raviralanaresh2
 
PPTX
Command Palatte in Odoo 18.1 Spreadsheet - Odoo Slides
Celine George
 
PPTX
YSPH VMOC Special Report - Measles Outbreak Southwest US 7-20-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
PPTX
Introduction to Probability(basic) .pptx
purohitanuj034
 
PPTX
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
PPTX
ENGLISH 8 WEEK 3 Q1 - Analyzing the linguistic, historical, andor biographica...
OliverOllet
 
My Thoughts On Q&A- A Novel By Vikas Swarup
Niharika
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
I INCLUDED THIS TOPIC IS INTELLIGENCE DEFINITION, MEANING, INDIVIDUAL DIFFERE...
parmarjuli1412
 
Applications of matrices In Real Life_20250724_091307_0000.pptx
gehlotkrish03
 
Cybersecurity: How to Protect your Digital World from Hackers
vaidikpanda4
 
Rules and Regulations of Madhya Pradesh Library Part-I
SantoshKumarKori2
 
Tips for Writing the Research Title with Examples
Thelma Villaflores
 
THE JEHOVAH’S WITNESSES’ ENCRYPTED SATANIC CULT
Claude LaCombe
 
Virus sequence retrieval from NCBI database
yamunaK13
 
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
DRUGS USED IN THERAPY OF SHOCK, Shock Therapy, Treatment or management of shock
Rajshri Ghogare
 
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
Stepwise procedure (Manually Submitted & Un Attended) Medical Devices Cases
MUHAMMAD SOHAIL
 
Applied-Statistics-1.pptx hardiba zalaaa
hardizala899
 
EXCRETION-STRUCTURE OF NEPHRON,URINE FORMATION
raviralanaresh2
 
Command Palatte in Odoo 18.1 Spreadsheet - Odoo Slides
Celine George
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 7-20-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Introduction to Probability(basic) .pptx
purohitanuj034
 
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
ENGLISH 8 WEEK 3 Q1 - Analyzing the linguistic, historical, andor biographica...
OliverOllet
 

Tuple in python

  • 1. TUPLE IN PYTHON COMPUTER SCIENCE(083) XII
  • 2. What is tuple?: A tuple is a collection of values or an ordered sequence of values similar to list. Elements of a tuple enclosed in a parenthesis ( ), separated by commas (,) . Syntax: tuple_name= (value1, value2,……..,valueN) Example: tup = (10, 20, 30, 40, 50 )
  • 3. HOW TO CREATE AND INITIALIZE TUPLE Method 1: If tuple is declare empty. tup1=( ) Method 2: Initialize tuple with value: If we want to store the numbers in a tuple. tup2= (1, 2, 30, 4, 15) If we want to store the words or string in a tuple. tup3= (‘MON’, ‘TUE’, ’WED’, ’THU’)
  • 4. HOW TO CREATE AND INITIALIZE TUPLE Example: If we want to store the characters in a tuple. tup4= (‘A’,’E’,’I’,’O’,’U’) Example: If we want to store the mixed information in a tuple. tup4= (“Kapil”, 13,”Class-IX”, 40)
  • 5. TO DISPLAY THE TUPLE Example: tup2= (10, 20, 30, 40, 50) print(tup2) ----------------Output------------- (10, 20, 30, 40, 50) Example: tup= (“Mango”, “Apple”,”Grapes”,”Oranges”) print(tup) ----------------Output------------- (‘Mango’, ‘Apple’, ’Grapes’, ’Oranges’)
  • 6. HOW TO CREATE AND INITIALIZE THE TUPLE USING TUPLE() CONSTRUCTOR Syntax: tuple_name=tuple(sequence or string) Example: tup1=tuple() Print(tup1) ----------output---------- ( ) tup4= tuple((‘A’,’E’,’I’,’O’,’U’)) print(tup4) If we want to store the characters in a list tup4= tuple(“AEIOU”) print(tup4) ---------Output---------- (‘A’, ‘E’,’I’,’O’,’U’)
  • 7. HOW TO CREATE AND INITIALIZE THE TUPLE USING TUPLE() CONSTRUCTOR Example: If we want to store the mixed information in a list. tup4= tuple((“Kapil”, 13,”Class-IX”, 40)) print(tup4) ----------------Output------------- (‘Kapil’, 13,’Class-IX’, 40) Example: If we want to store the numbers in a tuple. tup2=tuple((10, 20, 30, 40, 50)) print(tup2) ----------------Output------------- (10, 20, 30, 40, 50)
  • 8. HOW USER ENTER THE VALUES IN A TUPLE AT RUN TIME.
  • 9. We can use eval( ) method, which identifies the data type and evaluate them automatically. Example: no=eval(input(“Enter the no:”)) print(no) -------Input----------- Enter the no: 1,2,3,4,5,6,7,8,9 -----------Output------------- (1,2,3,4,5,6,7,8,9)
  • 10. Example: tup1=() x=1 while x<=5: no=int(input(“Enter the no:”)) tup1=tup1+(no,) x=x+1 print(tup1) ====OUTPUT===== Enter the no:10 Enter the no:20 Enter the no:30 Enter the no:40 Enter the no:50 (10, 20, 30, 40, 50)
  • 11. Accessing Tuple Elements Example: Let’s store no’s in a tuple no=(10,20,30,40,50,60,70,80) 0 1 2 3 4 5 6 7 10 20 30 40 50 60 70 80 -8 -7 -6 -5 -4 -3 -2 -1 Positive index Negative index
  • 12. Now To access these tuple let us discuss operations of tuple Tuple operations Indexing Slicing Repetition Concatenation Membership Testing
  • 13. Indexing Indexing specify the position of elements in a tuple or sequence and help us to access the value from the sequence separately. For Example: if we want to access the number 60 from a tuple given below using positive index number and 20 using negative number 0 1 2 3 4 5 6 7 10 20 30 40 50 60 70 80 -8 -7 -6 -5 -4 -3 -2 -1 Positive index Negative index
  • 14. Indexing 0 1 2 3 4 5 6 7 10 20 30 40 50 60 70 80 -8 -7 -6 -5 -4 -3 -2 -1 no=(10,20,30,40,50,60,70,80) print(no[4]) --------output-------- 50 No=(10,20,30,40,50,60,70,80) print(no[-6]) --------output------------- 30
  • 15. Slicing Slicing is an operation in which you can slice a particular range from a sequence. Syntax: tupname [start : stop : step] Where, start is the starting point Stop is the stopping point Step is the step size—also known as stride, and is optional. Its default value is 1
  • 16. Slicing Now let Us take one Example: print ( no [-3 : ] ) 60, 70, 80 print ( no [ 1 : 4 ] ) 20,30,40 Items from 1 to 3 0 1 2 3 4 5 6 7 10 20 30 40 50 60 70 80 -8 -7 -6 -5 -4 -3 -2 -1 no=(10,20,30,40,50,60,70,80)
  • 17. Concatenation It is a process in which tuple can be combine together with the help of ‘+’ operator. Example: t1=(10,20,30) t2=(1,2,3) In this t1 we add t2 and original t1 overwritet1=t1+t2 ------------output-------------- (10, 20, 30, 1, 2, 3) print(t1)
  • 18. Repetition Multiply ( * asterisk) operator replicates the tuple for specified number of times. Example: tup1=(1,2) print(tup1*3) ------------output-------------- (1, 2, 1, 2,1,2)
  • 19. It check whether a particular element or item is a member of that sequence or tuple or not. There are two operator: 1. in operator 2. not in operator Membership Testing: in operator: It returns true if element appears in the tuple, otherwise returns false. Example: tup1=(10,20,30,40) print(30 in tup1) ----------output----------- True
  • 20. Note: it will give True if value not exists inside the tuple not in operator: It returns true if element not appears in the tuple, otherwise returns false. Example: tup1=(10,20,30,40) print(50 not in tup1) ----------output----------- True
  • 21. Tuple functions len() count() It count number of times a specified value occurs in a tuple It returns the length of the tuple means count total number of elements in a tuple. tup=(1,2,3,4,5,6,7,8,9) print(len(tup)) -----Output------ 9 tup=(1,2,3,2,4,5,6,2,7,2,8) print(tup.count(2)) --------OUTPUT------- 4
  • 22. any() index() Searches the tuple for a specified value and returns the position of where it was found It return True, if a tuple is having at least one item.If the tuple is empty, it will return False. Tuple functions tup=(1,2,3,2,4,5,6,2,7,2,8) print(tup.index(2)) -----Output------ 1 tup=(1,2,3) print(any(tup)) -----Output------ True tup=() print(any(tup)) -----Output------ False If there are elements inside it display true If the tuple is empty it display False
  • 23. min() and max() sorted() It is used to sort the elements in a tuple. tup=(-10,25,-5,1,6,19,7) print(sorted(tup)) -----Output------ (-10, -5, 1, 6, 7, 19, 25) tup=(10,25,5,1,6,19,7) print("Max:",max(tup)," Min:",min(tup)) Max: 25 Min: 1
  • 24. Traversing Tuple or how to display the tuple elements using loops tup=(1,2,3,4,5,6,7,8,9) for x in range(0,len(tup)): print(tup[x]) -----Output------ 1 2 3 4 5 6 7 8 9 tup=(1,2,3,4,5,6,7,8,9) x=0 while x<len(tup): print(tup[x]) x=x+1