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

PPTX
Chapter 14 strings
Praveen M Jigajinni
 
PPTX
Unit 4 python -list methods
narmadhakin
 
PPTX
Handling of character strings C programming
Appili Vamsi Krishna
 
PPTX
Python Functions
Mohammed Sikander
 
PPTX
Python list
ArchanaBhumkar
 
PPTX
Strings in Java
Abhilash Nair
 
PDF
What is Dictionary In Python? Python Dictionary Tutorial | Edureka
Edureka!
 
PPTX
Ppt on Linked list,stack,queue
Srajan Shukla
 
Chapter 14 strings
Praveen M Jigajinni
 
Unit 4 python -list methods
narmadhakin
 
Handling of character strings C programming
Appili Vamsi Krishna
 
Python Functions
Mohammed Sikander
 
Python list
ArchanaBhumkar
 
Strings in Java
Abhilash Nair
 
What is Dictionary In Python? Python Dictionary Tutorial | Edureka
Edureka!
 
Ppt on Linked list,stack,queue
Srajan Shukla
 

What's hot (20)

PDF
Red black tree
Dr Sandeep Kumar Poonia
 
PPTX
Queue Implementation Using Array & Linked List
PTCL
 
PPTX
Recursion
Ssankett Negi
 
PPTX
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Muhammad Hammad Waseem
 
DOCX
Data Structures Using C Practical File
Rahul Chugh
 
PDF
Bca data structures linked list mrs.sowmya jyothi
Sowmya Jyothi
 
PPTX
Strings in Python
Amisha Narsingani
 
PPTX
Stack and Queue
Apurbo Datta
 
PDF
Python list
Mohammed Sikander
 
PPTX
Graph traversals in Data Structures
Anandhasilambarasan D
 
PPTX
Data types in python
RaginiJain21
 
PPT
Stack
srihariyenduri
 
PDF
Python programming : Files
Emertxe Information Technologies Pvt Ltd
 
PDF
Applications of stack
eShikshak
 
PPTX
Functions in c++
Rokonuzzaman Rony
 
PPTX
Datastructures in python
hydpy
 
PPTX
Heap sort
Ayesha Tahir
 
PDF
Python Workshop Part 2. LUG Maniapl
Ankur Shrivastava
 
PPT
Strings in c
vampugani
 
Red black tree
Dr Sandeep Kumar Poonia
 
Queue Implementation Using Array & Linked List
PTCL
 
Recursion
Ssankett Negi
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Muhammad Hammad Waseem
 
Data Structures Using C Practical File
Rahul Chugh
 
Bca data structures linked list mrs.sowmya jyothi
Sowmya Jyothi
 
Strings in Python
Amisha Narsingani
 
Stack and Queue
Apurbo Datta
 
Python list
Mohammed Sikander
 
Graph traversals in Data Structures
Anandhasilambarasan D
 
Data types in python
RaginiJain21
 
Python programming : Files
Emertxe Information Technologies Pvt Ltd
 
Applications of stack
eShikshak
 
Functions in c++
Rokonuzzaman Rony
 
Datastructures in python
hydpy
 
Heap sort
Ayesha Tahir
 
Python Workshop Part 2. LUG Maniapl
Ankur Shrivastava
 
Strings in c
vampugani
 
Ad

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
Tuple in Python class documnet pritened.
SravaniSravani53
 
PDF
Python Is Very most Important for Your Life Time.
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
 
Tuple in Python class documnet pritened.
SravaniSravani53
 
Python Is Very most Important for Your Life Time.
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
 

Recently uploaded (20)

PPTX
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
PDF
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
PPTX
ACUTE NASOPHARYNGITIS. pptx
AneetaSharma15
 
PPTX
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
PPTX
NOI Hackathon - Summer Edition - GreenThumber.pptx
MartinaBurlando1
 
DOCX
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
DOCX
UPPER GASTRO INTESTINAL DISORDER.docx
BANDITA PATRA
 
PDF
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
PPTX
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
PDF
Module 3: Health Systems Tutorial Slides S2 2025
Jonathan Hallett
 
PDF
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
PDF
The Picture of Dorian Gray summary and depiction
opaliyahemel
 
PPTX
Strengthening open access through collaboration: building connections with OP...
Jisc
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PPTX
Introduction and Scope of Bichemistry.pptx
shantiyogi
 
PPTX
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
PPTX
IMMUNIZATION PROGRAMME pptx
AneetaSharma15
 
PPTX
Congenital Hypothyroidism pptx
AneetaSharma15
 
PPTX
PREVENTIVE PEDIATRIC. pptx
AneetaSharma15
 
PPTX
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
ACUTE NASOPHARYNGITIS. pptx
AneetaSharma15
 
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
NOI Hackathon - Summer Edition - GreenThumber.pptx
MartinaBurlando1
 
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
UPPER GASTRO INTESTINAL DISORDER.docx
BANDITA PATRA
 
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
Module 3: Health Systems Tutorial Slides S2 2025
Jonathan Hallett
 
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
The Picture of Dorian Gray summary and depiction
opaliyahemel
 
Strengthening open access through collaboration: building connections with OP...
Jisc
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
Introduction and Scope of Bichemistry.pptx
shantiyogi
 
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
IMMUNIZATION PROGRAMME pptx
AneetaSharma15
 
Congenital Hypothyroidism pptx
AneetaSharma15
 
PREVENTIVE PEDIATRIC. pptx
AneetaSharma15
 
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 

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