Tuple
Tuple
Join
3 Tuples can be joined using the concatenation operator (+) to
create a new tuple.
Try Me! Add
Try Me! Remove
Try Me! Join
Tuple methods and operations
Tuple Methods Tuple Operations
Tuples have built-in methods Tuples support common
such as count() and index() for operations like concatenation,
easy data manipulation. repetition, and membership
These methods allow for testing.
efficient search and retrieval of
data within a tuple.
https://www.w3schools.com/python/python_tuples_methods.asp
Group Activity 1: Using count( ) and index( )
Methods with Tuples
Instructions:
1. Create a tuple named colors that contains several color values, with
some colors repeated. For example, use colors = ('red', 'blue', 'green',
'blue').
2. Use the count( ) method to find out how many times 'blue' appears in
the tuple.
3. Use the index( ) method to determine the position of 'green' in the
tuple.
4. Observe how these methods work to access and analyze data in
tuples.
Dictionary
Definition and characteristics of dictionaries
Python dictionaries are unordered collections of items
that store data in key-value pairs.
They are versatile and can store different types of data.
Dictionaries are commonly used for tasks such as
storing user information, configuration settings, and
more.
Definition and Characteristics of Dictionaries
Key-Value Pairs Unordered
Dictionaries are collections of key-
Dictionaries are unordered,
value pairs, where each key is
meaning that the elements do not
unique and is used to access its
have a specific order, unlike
corresponding value.
tuples.
Editing Updating
Modify dictionaries by Update the values of
adding or removing existing keys with new
key-value pairs as information or data.
needed.
Try Me! Edit
Try Me! Update
Dictionary methods and operations
Dictionary Methods Dictionary Operations
Dictionaries have built-in Similar to Tuple, Dictionary
methods such as clear() and support common operations
copy() for easy dictionary like concatenation and
manipulation. repetition.
https://www.w3schools.com/python/python_dictionaries_methods.asp
Group Activity 2: Copying and Modifying a
Dictionary
Instructions:
1. Imagine now that you want to create a dictionary to store color codes for
each color in the colors tuple. Create a dictionary named color_codes with
color names as keys and example color codes as values, like {'red':
'#FF0000', 'blue': '#0000FF', 'green': '#008000'}.
2. Make a copy of color_codes using the copy( ) method and assign it to a new
variable, new_color_codes.
3. In new_color_codes, add a new key-value pair for another color, such as
'yellow': '#FFFF00'.
4. Print both dictionaries to confirm that new_color_codes has been
modified, but color_codes remains unchanged.
Q&A