SlideShare a Scribd company logo
1 of 13
PYTHON PROGRAMMING WITH
WEB FRAMEWORKS – CSE304
This presentation contains the
concepts related to Tuples
Introduction
• Tuples are used to store multiple items in a single
variable.
• A tuple is a collection which is ordered and
unchangeable.
2
Why tuples?
• Suppose a method in your application depends on a
particular sequence of objects remaining the same
throughout the lifetime of the code.
• If you store these objects in a list, there is a chance
that some other method using the list will accidentally
alter it and thus break your method.
• Thus, in a way, a tuple offers a guarantee that a
particular collection of objects will remain fixed.
3
Tuples
• Tuples are immutable, so they can't be changed.
• As a result, you can't use any of the skills for adding, modifying,
or removing items.
• Example:
• If you have data that doesn't change, implementing it as tuple
will guarantee that it remains write-protected.
Tuples
• How to create a tuple
mytuple = (iteml, item2, . . .)
• Code that creates tuples
# a tuple of 5 floating-point numbers
stats = (48.0, 30.5, 20.2, 100.0, 48.0)
# a tuple of 6 strings
Ice_cream_flavors = (“Vennila”, “strawberry”,
“chocolate”, “pista”,”badam”)
5
Tuples
• Code that accesses items in a tuple
Ice_cream_flavors[0] # Vennila
Ice_cream_flavors[-1] # badam
Ice_cream_flavors[1:4] # (“strawberry”, “chocolate”,
“pista”)
• Code that unpacks a tuple
tuple_values = (1, 2, 3)
a, b, c = tuple_values # a = 1, b=2, c=3
6
Tuples
#function code
def calltup():
x=(1,2,3)
return(x)
#driver code
a,b,c=calltup()
print(a,b,c)
7
Tuples
Tuples provide just two methods,
• t.count(x), which returns the number of times object x occurs in
tuple t,and
• t.index(x), which returns the index position of the leftmost
occurrence of object x in tuple t.
Tuples can be used with the operators
• + (concatenation),
• * (replication), and
• [] (slice), and
• with in and not in to test for membership.
• The += and *= augmented assignment operators can be used
even though tuples are immutable
9
Method/Function Description
count()
Returns the number of occurrences of a
specified element in a tuple.
index()
Returns the index of the first occurrence of a
specified element in a tuple.
len() Returns the number of elements in a tuple.
sorted()
Returns a new tuple with the elements sorted
in ascending order.
min() Returns the smallest element in a tuple.
max() Returns the largest element in a tuple.
tuple() Converts an iterable object into a tuple.
Tuples - Example
Using tuple() method to create new tuple
• >>> t=tuple((1,2,3))
+ (concatenation operator usage in tuples)
• >>> t1=(4,5,6)
• >>> print(t+t1)
• (1, 2, 3, 4, 5, 6)
• >>> t3=t+t1
• >>> t3
• (1, 2, 3, 4, 5, 6)
• >>> t[:1] + (5,) + t[1:]
• (1, 5, 2, 3)
* (replication operator usage in tuples)
• >>> t*2
• (1, 2, 3, 1, 2, 3)
Finding length of a tuple
• len(t) returns 3
Tuples - Example
[] (slicing in tuples )
• >>> t[2]
• 3
+=, *= (augmented operator usage in tuples)
• >>> t2=()
• >>> t2+=t
• >>> t2
• (1, 2, 3)
• >>> t2*=2
• >>> t2
• (1, 2, 3, 1, 2, 3)
Count function in tuples:
• >>> t.count(1)
• 1
Index function in tuples:
• >>> t.index(1)
• 0
Nested Tuples
• In Python, a tuple can be defined inside another
tuple; called Nested tuple.
• In a nested tuple, each tuple is considered as an
element.
• The for loop will be useful to access all the elements
in a nested tuple.
• Toppers = (("Vinodini", 98.7), ("Soundarya",
97.5),("Tharani", 95.3), ("Saisri",93.8))
12
Nested Tuples - Example
Toppers = (("Vinodini", 98.7), ("Soundarya",
97.5),("Tharani", 95.3), ("Saisri",93.8))
for i in Toppers:
print(i)
13

More Related Content

Similar to 1.10 Tuples_sets_usage_applications_advantages.pptx

Q-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python.pptx
Q-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python.pptxQ-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python.pptx
Q-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python.pptx
kalai75
 

Similar to 1.10 Tuples_sets_usage_applications_advantages.pptx (20)

Python-Tuples
Python-TuplesPython-Tuples
Python-Tuples
 
Chapter 13 Tuples.pptx
Chapter 13 Tuples.pptxChapter 13 Tuples.pptx
Chapter 13 Tuples.pptx
 
Chapter 17 Tuples
Chapter 17 TuplesChapter 17 Tuples
Chapter 17 Tuples
 
Chapter 13 Tuples.pptx
Chapter 13 Tuples.pptxChapter 13 Tuples.pptx
Chapter 13 Tuples.pptx
 
Effective tuples in phyton template.pptx
Effective tuples in phyton template.pptxEffective tuples in phyton template.pptx
Effective tuples in phyton template.pptx
 
Arrays in programming
Arrays in programmingArrays in programming
Arrays in programming
 
An Introduction to Programming in Java: Arrays
An Introduction to Programming in Java: ArraysAn Introduction to Programming in Java: Arrays
An Introduction to Programming in Java: Arrays
 
Python programming UNIT III-Part-2.0.pptx
Python programming UNIT III-Part-2.0.pptxPython programming UNIT III-Part-2.0.pptx
Python programming UNIT III-Part-2.0.pptx
 
Lecture 09.pptx
Lecture 09.pptxLecture 09.pptx
Lecture 09.pptx
 
updated_tuple_in_python.pdf
updated_tuple_in_python.pdfupdated_tuple_in_python.pdf
updated_tuple_in_python.pdf
 
DSA-Day-2-PS.pptx
DSA-Day-2-PS.pptxDSA-Day-2-PS.pptx
DSA-Day-2-PS.pptx
 
Python Interview Questions And Answers
Python Interview Questions And AnswersPython Interview Questions And Answers
Python Interview Questions And Answers
 
Standard template library
Standard template libraryStandard template library
Standard template library
 
MODULE-2.pptx
MODULE-2.pptxMODULE-2.pptx
MODULE-2.pptx
 
Slicing in Python - What is It?
Slicing in Python - What is It?Slicing in Python - What is It?
Slicing in Python - What is It?
 
numpy.pdf
numpy.pdfnumpy.pdf
numpy.pdf
 
Q-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python.pptx
Q-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python.pptxQ-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python.pptx
Q-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python.pptx
 
Talk on Standard Template Library
Talk on Standard Template LibraryTalk on Standard Template Library
Talk on Standard Template Library
 
New c sharp3_features_(linq)_part_iii
New c sharp3_features_(linq)_part_iiiNew c sharp3_features_(linq)_part_iii
New c sharp3_features_(linq)_part_iii
 
Decision control units by Python.pptx includes loop, If else, list, tuple and...
Decision control units by Python.pptx includes loop, If else, list, tuple and...Decision control units by Python.pptx includes loop, If else, list, tuple and...
Decision control units by Python.pptx includes loop, If else, list, tuple and...
 

More from VGaneshKarthikeyan

More from VGaneshKarthikeyan (20)

Unit III Part I_Opertaor_Overloading.pptx
Unit III Part I_Opertaor_Overloading.pptxUnit III Part I_Opertaor_Overloading.pptx
Unit III Part I_Opertaor_Overloading.pptx
 
Linear_discriminat_analysis_in_Machine_Learning.pptx
Linear_discriminat_analysis_in_Machine_Learning.pptxLinear_discriminat_analysis_in_Machine_Learning.pptx
Linear_discriminat_analysis_in_Machine_Learning.pptx
 
K-Mean clustering_Introduction_Applications.pptx
K-Mean clustering_Introduction_Applications.pptxK-Mean clustering_Introduction_Applications.pptx
K-Mean clustering_Introduction_Applications.pptx
 
Numpy_defintion_description_usage_examples.pptx
Numpy_defintion_description_usage_examples.pptxNumpy_defintion_description_usage_examples.pptx
Numpy_defintion_description_usage_examples.pptx
 
Refined_Lecture-14-Linear Algebra-Review.ppt
Refined_Lecture-14-Linear Algebra-Review.pptRefined_Lecture-14-Linear Algebra-Review.ppt
Refined_Lecture-14-Linear Algebra-Review.ppt
 
randomwalks_states_figures_events_happenings.ppt
randomwalks_states_figures_events_happenings.pptrandomwalks_states_figures_events_happenings.ppt
randomwalks_states_figures_events_happenings.ppt
 
stochasticmodellinganditsapplications.ppt
stochasticmodellinganditsapplications.pptstochasticmodellinganditsapplications.ppt
stochasticmodellinganditsapplications.ppt
 
Neural_Networks_scalability_consntency.ppt
Neural_Networks_scalability_consntency.pptNeural_Networks_scalability_consntency.ppt
Neural_Networks_scalability_consntency.ppt
 
Lecture-4-Linear Regression-Gradient Descent Solution.ppt
Lecture-4-Linear Regression-Gradient Descent Solution.pptLecture-4-Linear Regression-Gradient Descent Solution.ppt
Lecture-4-Linear Regression-Gradient Descent Solution.ppt
 
1.3 Basic coding skills_tupels_sets_controlloops.ppt
1.3 Basic coding skills_tupels_sets_controlloops.ppt1.3 Basic coding skills_tupels_sets_controlloops.ppt
1.3 Basic coding skills_tupels_sets_controlloops.ppt
 
Python_basics_tuples_sets_lists_control_loops.ppt
Python_basics_tuples_sets_lists_control_loops.pptPython_basics_tuples_sets_lists_control_loops.ppt
Python_basics_tuples_sets_lists_control_loops.ppt
 
1.4 Work with data types and variables, numeric data, string data.pptx
1.4 Work with data types and variables, numeric data, string data.pptx1.4 Work with data types and variables, numeric data, string data.pptx
1.4 Work with data types and variables, numeric data, string data.pptx
 
Inheritance_with_its_types_single_multi_hybrid
Inheritance_with_its_types_single_multi_hybridInheritance_with_its_types_single_multi_hybrid
Inheritance_with_its_types_single_multi_hybrid
 
Refined_Lecture-8-Probability Review-2.ppt
Refined_Lecture-8-Probability Review-2.pptRefined_Lecture-8-Probability Review-2.ppt
Refined_Lecture-8-Probability Review-2.ppt
 
Refined_Lecture-13-Maximum Likelihood Estimators-Part-C.ppt
Refined_Lecture-13-Maximum Likelihood Estimators-Part-C.pptRefined_Lecture-13-Maximum Likelihood Estimators-Part-C.ppt
Refined_Lecture-13-Maximum Likelihood Estimators-Part-C.ppt
 
Refined_Lecture-15-Dimensionality Reduction-Uunspervised-PCA.ppt
Refined_Lecture-15-Dimensionality Reduction-Uunspervised-PCA.pptRefined_Lecture-15-Dimensionality Reduction-Uunspervised-PCA.ppt
Refined_Lecture-15-Dimensionality Reduction-Uunspervised-PCA.ppt
 
Bias-Variance_relted_to_ML.pdf
Bias-Variance_relted_to_ML.pdfBias-Variance_relted_to_ML.pdf
Bias-Variance_relted_to_ML.pdf
 
Refined_Lecture-1-Motivation & Applications.ppt
Refined_Lecture-1-Motivation & Applications.pptRefined_Lecture-1-Motivation & Applications.ppt
Refined_Lecture-1-Motivation & Applications.ppt
 
Lecture-4-Linear Regression-Gradient Descent Solution.PPTX
Lecture-4-Linear Regression-Gradient Descent Solution.PPTXLecture-4-Linear Regression-Gradient Descent Solution.PPTX
Lecture-4-Linear Regression-Gradient Descent Solution.PPTX
 
13.Data Conversion.pptx
13.Data Conversion.pptx13.Data Conversion.pptx
13.Data Conversion.pptx
 

Recently uploaded

Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
MsecMca
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 

Recently uploaded (20)

VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdf
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 

1.10 Tuples_sets_usage_applications_advantages.pptx

  • 1. PYTHON PROGRAMMING WITH WEB FRAMEWORKS – CSE304 This presentation contains the concepts related to Tuples
  • 2. Introduction • Tuples are used to store multiple items in a single variable. • A tuple is a collection which is ordered and unchangeable. 2
  • 3. Why tuples? • Suppose a method in your application depends on a particular sequence of objects remaining the same throughout the lifetime of the code. • If you store these objects in a list, there is a chance that some other method using the list will accidentally alter it and thus break your method. • Thus, in a way, a tuple offers a guarantee that a particular collection of objects will remain fixed. 3
  • 4. Tuples • Tuples are immutable, so they can't be changed. • As a result, you can't use any of the skills for adding, modifying, or removing items. • Example: • If you have data that doesn't change, implementing it as tuple will guarantee that it remains write-protected.
  • 5. Tuples • How to create a tuple mytuple = (iteml, item2, . . .) • Code that creates tuples # a tuple of 5 floating-point numbers stats = (48.0, 30.5, 20.2, 100.0, 48.0) # a tuple of 6 strings Ice_cream_flavors = (“Vennila”, “strawberry”, “chocolate”, “pista”,”badam”) 5
  • 6. Tuples • Code that accesses items in a tuple Ice_cream_flavors[0] # Vennila Ice_cream_flavors[-1] # badam Ice_cream_flavors[1:4] # (“strawberry”, “chocolate”, “pista”) • Code that unpacks a tuple tuple_values = (1, 2, 3) a, b, c = tuple_values # a = 1, b=2, c=3 6
  • 8. Tuples Tuples provide just two methods, • t.count(x), which returns the number of times object x occurs in tuple t,and • t.index(x), which returns the index position of the leftmost occurrence of object x in tuple t. Tuples can be used with the operators • + (concatenation), • * (replication), and • [] (slice), and • with in and not in to test for membership. • The += and *= augmented assignment operators can be used even though tuples are immutable
  • 9. 9 Method/Function Description count() Returns the number of occurrences of a specified element in a tuple. index() Returns the index of the first occurrence of a specified element in a tuple. len() Returns the number of elements in a tuple. sorted() Returns a new tuple with the elements sorted in ascending order. min() Returns the smallest element in a tuple. max() Returns the largest element in a tuple. tuple() Converts an iterable object into a tuple.
  • 10. Tuples - Example Using tuple() method to create new tuple • >>> t=tuple((1,2,3)) + (concatenation operator usage in tuples) • >>> t1=(4,5,6) • >>> print(t+t1) • (1, 2, 3, 4, 5, 6) • >>> t3=t+t1 • >>> t3 • (1, 2, 3, 4, 5, 6) • >>> t[:1] + (5,) + t[1:] • (1, 5, 2, 3) * (replication operator usage in tuples) • >>> t*2 • (1, 2, 3, 1, 2, 3) Finding length of a tuple • len(t) returns 3
  • 11. Tuples - Example [] (slicing in tuples ) • >>> t[2] • 3 +=, *= (augmented operator usage in tuples) • >>> t2=() • >>> t2+=t • >>> t2 • (1, 2, 3) • >>> t2*=2 • >>> t2 • (1, 2, 3, 1, 2, 3) Count function in tuples: • >>> t.count(1) • 1 Index function in tuples: • >>> t.index(1) • 0
  • 12. Nested Tuples • In Python, a tuple can be defined inside another tuple; called Nested tuple. • In a nested tuple, each tuple is considered as an element. • The for loop will be useful to access all the elements in a nested tuple. • Toppers = (("Vinodini", 98.7), ("Soundarya", 97.5),("Tharani", 95.3), ("Saisri",93.8)) 12
  • 13. Nested Tuples - Example Toppers = (("Vinodini", 98.7), ("Soundarya", 97.5),("Tharani", 95.3), ("Saisri",93.8)) for i in Toppers: print(i) 13