0% found this document useful (0 votes)
3 views4 pages

8.python Dictionaries

The document provides an overview of Python dictionaries, highlighting their characteristics such as being mutable, indexed by unique keys, and storing data in key-value pairs. It covers how to access, modify, add, remove items, check for key existence, and determine the length of a dictionary, along with methods and the ability to nest dictionaries. Additionally, it mentions the use of the dict() constructor for creating dictionaries.

Uploaded by

KARTHIKEYAN S
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)
3 views4 pages

8.python Dictionaries

The document provides an overview of Python dictionaries, highlighting their characteristics such as being mutable, indexed by unique keys, and storing data in key-value pairs. It covers how to access, modify, add, remove items, check for key existence, and determine the length of a dictionary, along with methods and the ability to nest dictionaries. Additionally, it mentions the use of the dict() constructor for creating dictionaries.

Uploaded by

KARTHIKEYAN S
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

[Link].

com

Python Dictionaries

1. Introduction to Dictionaries

• A dictionary is a collection that is:


o ordered (unordered as of Python 3.6 and earlier)
o Mutable (changeable)
o Indexed by keys, not numbers
• Dictionaries store data in key-value pairs.
• Keys must be unique and immutable (e.g., strings, numbers, tuples).
• Values can be of any data type.
• Dictionaries are written using curly braces {}.

2. Accessing Dictionary Items

• Use the key to access corresponding value.


• Syntax: dictionary[key]

4. Change Dictionary Items

• Modify value using its key.


• Syntax: dictionary[key] = new value

1
[Link]

5. Add Items to Dictionary

• Add new key-value pair.


• Syntax: dictionary[key] = new value

6. Remove Items

• Use pop(key), popitem() or del.

7. Check if Key Exists

• Use in or not in.

2
[Link]

8. Dictionary Length

• Use len() to count key-value pairs.

9. Dictionary Constructor

• Create dictionary using dict() constructor.

10. Dictionary Methods

• keys(), values(), items(), update(), clear()

3
[Link]

11. Nested Dictionary

• Dictionaries can contain other dictionaries as values.

You might also like