SlideShare a Scribd company logo
1 of 47
TUPLE
Tuple can be created in many ways.
1. tuple can be created in the following manner
by writing values of different data types in the
()
T=(1,”aman”,1.5)
2. single value tuple to be created by writing
single value followed by comma.
eg:-T=(1,)
TUPLE
If single value tuple is written in the following
manner then it will be taking the data type of
the value which is assigned to the variable
eg:-T=(1)
T will be identified as a integer variable.
Eg-t=(“aman”)
t will be identified as a string variable
TUPLE
3. Empty Tuple can be created in the following
manner
t=()
print(t)
4. Empty tuple can also be created by using
tuple function
t-=tuple()
Print(t)
OUTPUT:-
()
()
TUPLE
5. Tuple can be created by using tuple function
and passing existing tuple as a parameter
T1=(1,2,3,4)
print(T1)
print(id(T1))
T2=tuple(T1)
print(T2)
print(id(T2))
T3=T2
print(T3)
print(id(T3))
TUPLE
OUTPUT:
(1, 2, 3, 4)
1970366848912
(1, 2, 3, 4)
1970366848912
(1, 2, 3, 4)
1970366848912
All are referring to same location
TUPLE
6. Tuple can be created by using tuple() function
and passing existing list as a parameter.
l=[10,20,0,40]
print(l)
print(id(l))
t=tuple(l)
print(t)
print(id(t))
TUPLE
OUTPUT:-
[10, 20, 0, 40]
1629910642048
(10, 20, 0, 40)
1627794510608
Both list and tuple are referring to different
locations.
TUPLE
7. Tuple can also be created by passing string as
a parameter
st="WELCOME"
t=tuple(st)
print(st)
print(id(st))
print(t)
print(id(t))
TUPLE
OUTPUT:-
WELCOME
3004542942832
('W', 'E', 'L', 'C', 'O', 'M', 'E')
3004542482368
TUPLE
8. Tuple can be created by using the eval
function.
t=eval(input ("accept values into the tuple"))
print(t)
Output:
accept values into the tuple(1,2,3,4,5)
(1, 2, 3, 4, 5)
TUPLE
9. Tuple can also be created by using “replication
operator” in the following manner:
T=(1,2,3)
T1=T*3
print(T1)
OUTPUT:-
(1,2,3,1,2,3,1,2,3)
TUPLE
10. Nested tuple can be created in the following
manner
T=(1,2,3,(4,5,6))
Print(T[3][-1])
OUTPUT:-
6
TUPLE
11. List can be inside the nested tuple
T-(11,22,33,[1,2,3])
OUTPUT:-
(11, 22, 33,[1,2,3])
t=(11,22,33,[1,2,3])
print(t)
t[3][-1]=33
print(t)
OUTPUT:-
(11, 22, 33,[1,2,33])
TUPLE
12. New tuple can be created by extracting the
slice from the existing tuple.
t=(11,22,33,44,55)
nt=t[2:20]
print(t)
print(nt)
Output:-
(11, 22, 33, 44, 55)
(33, 44, 55)
TUPLE
13. New tuple can be created by by joining two
tuples using concatenation ‘+’
t1=(11,22,33,44,55)
t2=(66,77)
t3=t1+t2
Print(t1)
Print(t2)
Print(t3)
TUPLE
OUTPUT:
(11,22,33,44,55)
(66,77)
(11,22,33,44,55,66,77)
TUPLE
Accessing an individual element can be done in
the following manner
T=(11,22,33,44,55)
Print(T[2])
Output:
33
In the case of tuple, individual item assignment
is not possible.
T[2]=222---is wrong.
TUPLE
t=(11,22,33,[1,2,3])
print(t)
t[3][-1]=33
print(t)
OUTPUT:-
(11,22,33,[1,2,3])
(11,22,33,[1,2,33])
TUPLE
MEMBERSHIP OPERATORS
t=(11,22,33,[55,66,77],[88,99],100)
print (55 in t)
print(22 in t)
print([55,66,77] in t)
print([55,66,777] in t)
print ([55,66,77] not in t)
TUPLE
OUTPUT:-
False
True
True
False
False
TUPLE
LOGICAL OPERATORS
t=(11,22,33,[55,66,77],[88,99],100)
print(t[0] and 100)
print (0 or t[3])
print(t and 0)
TUPLE
OUTPUT:-
100
[55, 66, 77]
0
TUPLE
Tuple slices:-
t=(1,"aman",20,12.5,89.5,"x",[10,23,45],89)
print(t[2:5:1])
print(t[0: :])
print(t[6: :1])
print(t[ :len(t):])
print(t[ :(len(t)+20):])
print(t[0:34:1])
print(t[0:56:1])
TUPLE
• OUTPUT:-
(20, 12.5, 89.5)
(1, 'aman', 20, 12.5, 89.5, 'x', [10, 23, 45], 89)
([10, 23, 45], 89)
(1, 'aman', 20, 12.5, 89.5, 'x', [10, 23, 45], 89)
(1, 'aman', 20, 12.5, 89.5, 'x', [10, 23, 45], 89)
(1, 'aman', 20, 12.5, 89.5, 'x', [10, 23, 45], 89)
(1, 'aman', 20, 12.5, 89.5, 'x', [10, 23, 45], 89)
TUPLE
TUPLE-FUNCTIONS
1. len()- is used to get the length of the tuple.
t=(11,22,33,44)
L=len(t)
Print(L)
OUTPUT:
4
TUPLE
2.sum(t) –is used to get total of all the values
present in the tuple
t=(10,20,30,40,50,30)
print(t)
print("sum")
print(sum(t))
OUTPUT:-
SUM
180
TUPLE
3. TUPLE.COUNT(VALUE)- this function will find
out how many times the value exists in the
tuple and returns the value
t=(10,20,30,40,50,30)
print(t)
print("count")
print(t.count(30))
print(t.count(70))
print(t.count(80))
TUPLE
Output:-
count
2
0
0
TUPLE
4. tuple.index(value)-This function is used to
find out the index of the value which is passed
as a parameter.
If the value is not present in the tuple then value
error will be thrown
t=(10,20,30,40,50,30)
print(t.index(50))
#print(t.index(80))
TUPLE
OUTPUT
4
VALUE ERROR
TUPLE
• t1=(2,3,4,5)
• t2=(1,2,3)
• t3=t1+t2
• print(t3)
• print(t3.index(3,0))
• print(t3)
TUPLE
OUTPUT
(2, 3, 4, 5, 1, 2, 3)
1
(2, 3, 4, 5, 1, 2, 3)
TUPLE
5. del() function can be used to delete the tuple
T=(10,20,30,40,50)
Print(T)
Del T
(10,20,30,40,50)
T not defined
TUPLE
6.max(tuple)-This function extracts the maximum
value out of the all values of the tuple
t=(111,444,222,666,555)
print(t)
Print(“Max()”)
print(max(t))
7.min(t)-This function extracts the minimum
value out of the all values of the tuple
t=(111,444,222,666,555)
Print(“min()”)
print(min(t))
TUPLE
Output:
(111,444,222,666,555)
Max()
666
Min()
111
TUPLE
8. sorted(tuple)-This function will return sorted values of the
tuple without making any change in the values of the tuple.
The sorted values will be returned in the form of a list.
t=(10,30,30,60,50,20)
print(t)
print("using sorted()")
t1=sorted(t)
print(t1)
print(t)
TUPLE
OUTPUT
(10, 30, 30, 60, 50, 20)
using sorted()
[10, 20, 30, 30, 50, 60]
(10, 30, 30, 60, 50, 20)
TUPLE
• Packing and Unpacking
The process extracting values from the tuple and
assigning to different variables is known as
unpacking.
The number of variables used left to the “=“
should be equal to the length of the tuple.
TUPLE
t=(10,20,30,40)
print(t)
a,b,c,d=t
print(a)
print(b)
print(c)
print(d)
TUPLE
OUTPUT
(10, 20, 30, 40)
10
20
30
40
TUPLE
PACKING is the process where individual variables to be written
to the right side of the “=“
If the programmer wants to change the values of the tuple, first
unpacking to different variables to be done then manipulate
the values as per the requirement and then pack the variable
into a tuple as shown in the example.
The id of tuple is different from the id of the tuple after
unpacking .
TUPLE
t=(10,20,30,40)
print(t)
a,b,c,d=t
a=a+25
b=b-10
c=c+20
d=d-5
t=a,b,c,d
print(t)
TUPLE
a=100
b=200
c=300
t=a,b,c
print(t)
t=a
print(t)
t=a,
print(t)
TUPLE
OUTPUT
(100, 200, 300)
100
(100,)
TUPLE
TUPLE
TUPLE

More Related Content

Similar to TUPLE.ppt

Find the compact trigonometric Fourier series for the periodic signal.pdf
Find the compact trigonometric Fourier series for the periodic signal.pdfFind the compact trigonometric Fourier series for the periodic signal.pdf
Find the compact trigonometric Fourier series for the periodic signal.pdf
arihantelectronics
 

Similar to TUPLE.ppt (20)

Ch2
Ch2Ch2
Ch2
 
Python programming -Tuple and Set Data type
Python programming -Tuple and Set Data typePython programming -Tuple and Set Data type
Python programming -Tuple and Set Data type
 
The basics and design of lua table
The basics and design of lua tableThe basics and design of lua table
The basics and design of lua table
 
Python programming : List and tuples
Python programming : List and tuplesPython programming : List and tuples
Python programming : List and tuples
 
updated_tuple_in_python.pdf
updated_tuple_in_python.pdfupdated_tuple_in_python.pdf
updated_tuple_in_python.pdf
 
Contemporary communication systems 1st edition mesiya solutions manual
Contemporary communication systems 1st edition mesiya solutions manualContemporary communication systems 1st edition mesiya solutions manual
Contemporary communication systems 1st edition mesiya solutions manual
 
About RNN
About RNNAbout RNN
About RNN
 
About RNN
About RNNAbout RNN
About RNN
 
Find the compact trigonometric Fourier series for the periodic signal.pdf
Find the compact trigonometric Fourier series for the periodic signal.pdfFind the compact trigonometric Fourier series for the periodic signal.pdf
Find the compact trigonometric Fourier series for the periodic signal.pdf
 
C & S UNIT-1 WAVEFORM SYNTHESIZATION.pptx
C & S UNIT-1 WAVEFORM SYNTHESIZATION.pptxC & S UNIT-1 WAVEFORM SYNTHESIZATION.pptx
C & S UNIT-1 WAVEFORM SYNTHESIZATION.pptx
 
Sheet 1
Sheet 1Sheet 1
Sheet 1
 
03 Cap 2 - fourier-analysis-2015.pdf
03 Cap 2 - fourier-analysis-2015.pdf03 Cap 2 - fourier-analysis-2015.pdf
03 Cap 2 - fourier-analysis-2015.pdf
 
Ct signal operations
Ct signal operationsCt signal operations
Ct signal operations
 
SIGNAL OPERATIONS
SIGNAL OPERATIONSSIGNAL OPERATIONS
SIGNAL OPERATIONS
 
Lecture-15-Tuples-and-Dictionaries-Oct23-2018.pptx
Lecture-15-Tuples-and-Dictionaries-Oct23-2018.pptxLecture-15-Tuples-and-Dictionaries-Oct23-2018.pptx
Lecture-15-Tuples-and-Dictionaries-Oct23-2018.pptx
 
Dynamic table
Dynamic tableDynamic table
Dynamic table
 
21 5 ztransform
21 5 ztransform21 5 ztransform
21 5 ztransform
 
‏‏chap6 list tuples.pptx
‏‏chap6 list tuples.pptx‏‏chap6 list tuples.pptx
‏‏chap6 list tuples.pptx
 
Google TensorFlow Tutorial
Google TensorFlow TutorialGoogle TensorFlow Tutorial
Google TensorFlow Tutorial
 
optimal control principle slided
optimal control principle slidedoptimal control principle slided
optimal control principle slided
 

Recently uploaded

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Recently uploaded (20)

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 

TUPLE.ppt