0% found this document useful (0 votes)
4 views2 pages

? Chapter 10

The document explains tuples and dictionaries in Python, highlighting that tuples are ordered, immutable collections of elements, while dictionaries are mutable mappings of unique keys to values. It covers how to access tuple elements, perform operations like concatenation and repetition, and the structure and creation of dictionaries. Additionally, it discusses dictionary operations including membership checks and manipulation methods.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

? Chapter 10

The document explains tuples and dictionaries in Python, highlighting that tuples are ordered, immutable collections of elements, while dictionaries are mutable mappings of unique keys to values. It covers how to access tuple elements, perform operations like concatenation and repetition, and the structure and creation of dictionaries. Additionally, it discusses dictionary operations including membership checks and manipulation methods.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

TUPLES AND DICTIONARIES

1. What is tuples?
• A tuple is a ordered collection of sequence of elements of different data type such as integer,
float, string, list or even a tuple.
• Elements of tuples are enclosed in parenthesis ().And are separated by commas.
• Like list & string elements of tuple can be accessed using index value, starting from zero.

2. Accessing elements in a tuple?


• Elements of a tuple can be accessed in the same way as a list or a string using indexing and
slicing.

3. tuple is immutable?
• Tuple is immutable data type.
• It means that the elements of a tuple cannot be changed after it has been created.
• An attempt to do this would lead to an error.

4. What is tuple operations


Concatenation
• Python allows us to join tuples using concatenation operator denoted by symbol +.
• We can also create a new tuple which contains the result of this concatenation operator.
• Concatenation operator can also be used for extending an existing tuple.
• When we extend our tuple using concatenation a new tuple is created.

Repetition
• repetition operator is denoted by the symbol *.
• It is used to repeat elements of a tuple.
• We can repeat the tuple elements.
• the repetition operator requires first operand to be the tuple and 2nd operand to be the integer
only.

Membership
• the in operator checks if the element is present in the tuple and returns true, if else returns false.
• The not in operator returns true if the element is present in the tuple,. If else returns false

Slicing
• Say something like string and list it can be applied in tuple also.

DICTIONARIES
1. what is dictionary?
• The data type dictionary fall under mapping.
• it is a mapping between a set of keys and a set of values.
• A key is separated from its value by a : and Consecutive items are separated by commas.
• Items in dictionaries are unordered,
• so we may not get back the data in same order in which we had entered the data initially in the
dictionary.

2. To create a dictionary?
• the items entered are separated by commas and enclosed in curly braces.
• each item is a key value pair, separate it through :
• keys in the dictionary must be unique and should be of any immutable data type.
• The values can be repeated and can be of any other type.

3. Dictionaries are mutable?


• dictionaries are mutable which implies that the contents of a dictionary can be changed after
it has been created.

4. Dictionary operations
Membership
• The membership operator in checks if the item is present in the dictionary and returns true,
else returns false.
• Also not in. operator…
Traversing a dictionary.

5.Manipulating the dictionary.


• Programs show the application of those manipulation method on a dictionary.
Program dictionary odd of.

You might also like