SlideShare a Scribd company logo
1 of 12
Download to read offline
Tuple Operation and Tuple
Assignment in Python
Tuple Operation and Tuple
Assignment in Python
WHAT ARE TUPLES
TUPLE
TUPLE
A Tuple is an ordered collection
of elements in Python.
1.
2. Tuples in Python are both immutable
(cannot be changed) and ordered (element
sequence is preserved).
3. Tuples are used for storing related
data, returning multiple values from
functions, and as keys in dictionaries.
Tuples are created using
parentheses () and separating
values with commas.
creating tuple
This code snippet defines a tuple named my_tuple with three
elements: an integer, a string, and a floating-point number. Tuples
can contain a mix of different data types, and they preserve the order
of elements, making them a versatile and useful data structure in
Python.
You can acces elements in tuple using indexing by specifying the position of
the element within square brackets.the indexing starts at 0 for the first
element in the tuple
Tuples in python are zero indexed, meaning the first element is at index 0,the
second element is at index 1 and so on
Accessing Tuple
Elements
Concatenation: Concatenation is the process of combining
two or more tuples to create a new tuple. You can achieve
this by using the + operator.
Tuple Operations -
Concatenation
Tuple repetition allows you to create a new tuple by repeating an existing tuple
multiple times. You can achieve this using the * operator followed by the number
of times you want to repeat the tuple.
Here's how to use the * operator for tuple repetition:
In this example, original_tuple is repeated three times to create
repeated_tuple, which contains the elements from the original tuple
repeated in the specified order and number of times.
Tuple Operations -
Repetition
Tuple slicing is a technique in Python that allows
you to extract a portion of a tuple, creating a new
tuple containing those elements. Slicing is done
using the colon (:) notation within square
brackets and consists of two indices: the starting
index (inclusive) and the ending index (exclusive).
Here's how to use the slicing
notation for tuple slicing:
Tuple Operations -
Slicing
Tuple Assignment
Tuple Assignment
Tuple assignment is a way to
assign multiple values to
multiple variables at once
using tuples, enabling concise
assignments and value
swapping.
Assigning multiple values to variables:
Swapping variable values:
Swapping Values
with Tuples
Swapping in a tuple means exchanging the
positions or values of elements within the
tuple, typically using tuple assignment to
achieve this interchange.
Tuples are immutable, ordered sequences in Python. They
offer two methods: count() for counting occurrences of a
specific value in the tuple and index() for finding the index
of the first occurrence of a specified value. Tuples provide
data integrity and ordered storage.
Tuple Methods
CONCLUSION
"In conclusion, we've explored the world of tuples in Python, and we've learned that they are like
sealed envelopes, holding valuable information that can't be altered once sealed. We've seen how to
create tuples, access their elements, and use various operations to manipulate them in creative ways.
Tuples might seem simple, but they can be incredibly powerful and versatile tools in Python, helping
you organize and work with data effectively. So, I encourage you to experiment and have fun with
tuples in your Python projects. They can simplify your code and add a touch of creativity to your
programming journey
Thank you

More Related Content

Similar to Tuple Operation and Tuple Assignment in Python.pdf

CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docxCS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
faithxdunce63732
 

Similar to Tuple Operation and Tuple Assignment in Python.pdf (20)

Tuples-and-Dictionaries.pptx
Tuples-and-Dictionaries.pptxTuples-and-Dictionaries.pptx
Tuples-and-Dictionaries.pptx
 
Python Collections
Python CollectionsPython Collections
Python Collections
 
Python tuple
Python   tuplePython   tuple
Python tuple
 
Python Tuple.pdf
Python Tuple.pdfPython Tuple.pdf
Python Tuple.pdf
 
13- Data and Its Types presentation kafss
13- Data and Its Types presentation kafss13- Data and Its Types presentation kafss
13- Data and Its Types presentation kafss
 
PYTHON LISTsjnjsnljnsjnosojnosojnsojnsjsn.pptx
PYTHON LISTsjnjsnljnsjnosojnosojnsojnsjsn.pptxPYTHON LISTsjnjsnljnsjnosojnosojnsojnsjsn.pptx
PYTHON LISTsjnjsnljnsjnosojnosojnsojnsjsn.pptx
 
Python Datatypes by SujithKumar
Python Datatypes by SujithKumarPython Datatypes by SujithKumar
Python Datatypes by SujithKumar
 
Presentation on python data type
Presentation on python data typePresentation on python data type
Presentation on python data type
 
Lecture 09.pptx
Lecture 09.pptxLecture 09.pptx
Lecture 09.pptx
 
set.pptx
set.pptxset.pptx
set.pptx
 
List and tuple in python
List and tuple in pythonList and tuple in python
List and tuple in python
 
Arrays in programming
Arrays in programmingArrays in programming
Arrays in programming
 
MODULE-2.pptx
MODULE-2.pptxMODULE-2.pptx
MODULE-2.pptx
 
updated_tuple_in_python.pdf
updated_tuple_in_python.pdfupdated_tuple_in_python.pdf
updated_tuple_in_python.pdf
 
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docxCS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
 
AI_2nd Lab.pptx
AI_2nd Lab.pptxAI_2nd Lab.pptx
AI_2nd Lab.pptx
 
2. Values and Data types in Python.pptx
2. Values and Data types in Python.pptx2. Values and Data types in Python.pptx
2. Values and Data types in Python.pptx
 
python (1).pdf
python (1).pdfpython (1).pdf
python (1).pdf
 
computer science tuple in python project.pdf
computer science tuple in python project.pdfcomputer science tuple in python project.pdf
computer science tuple in python project.pdf
 
Data Types In Python.pptx
Data Types In Python.pptxData Types In Python.pptx
Data Types In Python.pptx
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 

Tuple Operation and Tuple Assignment in Python.pdf

  • 1. Tuple Operation and Tuple Assignment in Python Tuple Operation and Tuple Assignment in Python
  • 2. WHAT ARE TUPLES TUPLE TUPLE A Tuple is an ordered collection of elements in Python. 1. 2. Tuples in Python are both immutable (cannot be changed) and ordered (element sequence is preserved). 3. Tuples are used for storing related data, returning multiple values from functions, and as keys in dictionaries.
  • 3. Tuples are created using parentheses () and separating values with commas. creating tuple This code snippet defines a tuple named my_tuple with three elements: an integer, a string, and a floating-point number. Tuples can contain a mix of different data types, and they preserve the order of elements, making them a versatile and useful data structure in Python.
  • 4. You can acces elements in tuple using indexing by specifying the position of the element within square brackets.the indexing starts at 0 for the first element in the tuple Tuples in python are zero indexed, meaning the first element is at index 0,the second element is at index 1 and so on Accessing Tuple Elements
  • 5. Concatenation: Concatenation is the process of combining two or more tuples to create a new tuple. You can achieve this by using the + operator. Tuple Operations - Concatenation
  • 6. Tuple repetition allows you to create a new tuple by repeating an existing tuple multiple times. You can achieve this using the * operator followed by the number of times you want to repeat the tuple. Here's how to use the * operator for tuple repetition: In this example, original_tuple is repeated three times to create repeated_tuple, which contains the elements from the original tuple repeated in the specified order and number of times. Tuple Operations - Repetition
  • 7. Tuple slicing is a technique in Python that allows you to extract a portion of a tuple, creating a new tuple containing those elements. Slicing is done using the colon (:) notation within square brackets and consists of two indices: the starting index (inclusive) and the ending index (exclusive). Here's how to use the slicing notation for tuple slicing: Tuple Operations - Slicing
  • 8. Tuple Assignment Tuple Assignment Tuple assignment is a way to assign multiple values to multiple variables at once using tuples, enabling concise assignments and value swapping. Assigning multiple values to variables: Swapping variable values:
  • 9. Swapping Values with Tuples Swapping in a tuple means exchanging the positions or values of elements within the tuple, typically using tuple assignment to achieve this interchange.
  • 10. Tuples are immutable, ordered sequences in Python. They offer two methods: count() for counting occurrences of a specific value in the tuple and index() for finding the index of the first occurrence of a specified value. Tuples provide data integrity and ordered storage. Tuple Methods
  • 11. CONCLUSION "In conclusion, we've explored the world of tuples in Python, and we've learned that they are like sealed envelopes, holding valuable information that can't be altered once sealed. We've seen how to create tuples, access their elements, and use various operations to manipulate them in creative ways. Tuples might seem simple, but they can be incredibly powerful and versatile tools in Python, helping you organize and work with data effectively. So, I encourage you to experiment and have fun with tuples in your Python projects. They can simplify your code and add a touch of creativity to your programming journey