Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Adding Items | Dictionary
Python Data Structures
course content

Course Content

Python Data Structures

Python Data Structures

1. List
2. Dictionary
3. Tuple
4. Set
5. For deleting

bookAdding Items

Let's build a dictionary named student.

12
student = {'first name': 'Ann', 'last name': 'Elliot', 'city': 'New York'} print(student)
copy

Here's how you can add a key-value pair to a dictionary.

123
student = {'first name': 'Ann', 'last name': 'Elliot', 'city': 'New York'} student['country'] = 'USA' print(student)
copy

The student dictionary includes these pairs:

KeyValue
'first name''Ann'
'last name''Elliot'
'city''New York'
'country''USA'

Note

Single ' ' and double " " quotes in Python are interchangeable and equivalent.

Task

  1. Construct the following dictionary: 'name': 'Max', 'position': 'data scientist', 'level': 'junior';
  2. To the existing dictionary, append a new key named experience (as a string) with the value of 1.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 4
toggle bottom row

bookAdding Items

Let's build a dictionary named student.

12
student = {'first name': 'Ann', 'last name': 'Elliot', 'city': 'New York'} print(student)
copy

Here's how you can add a key-value pair to a dictionary.

123
student = {'first name': 'Ann', 'last name': 'Elliot', 'city': 'New York'} student['country'] = 'USA' print(student)
copy

The student dictionary includes these pairs:

KeyValue
'first name''Ann'
'last name''Elliot'
'city''New York'
'country''USA'

Note

Single ' ' and double " " quotes in Python are interchangeable and equivalent.

Task

  1. Construct the following dictionary: 'name': 'Max', 'position': 'data scientist', 'level': 'junior';
  2. To the existing dictionary, append a new key named experience (as a string) with the value of 1.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 4
toggle bottom row

bookAdding Items

Let's build a dictionary named student.

12
student = {'first name': 'Ann', 'last name': 'Elliot', 'city': 'New York'} print(student)
copy

Here's how you can add a key-value pair to a dictionary.

123
student = {'first name': 'Ann', 'last name': 'Elliot', 'city': 'New York'} student['country'] = 'USA' print(student)
copy

The student dictionary includes these pairs:

KeyValue
'first name''Ann'
'last name''Elliot'
'city''New York'
'country''USA'

Note

Single ' ' and double " " quotes in Python are interchangeable and equivalent.

Task

  1. Construct the following dictionary: 'name': 'Max', 'position': 'data scientist', 'level': 'junior';
  2. To the existing dictionary, append a new key named experience (as a string) with the value of 1.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Let's build a dictionary named student.

12
student = {'first name': 'Ann', 'last name': 'Elliot', 'city': 'New York'} print(student)
copy

Here's how you can add a key-value pair to a dictionary.

123
student = {'first name': 'Ann', 'last name': 'Elliot', 'city': 'New York'} student['country'] = 'USA' print(student)
copy

The student dictionary includes these pairs:

KeyValue
'first name''Ann'
'last name''Elliot'
'city''New York'
'country''USA'

Note

Single ' ' and double " " quotes in Python are interchangeable and equivalent.

Task

  1. Construct the following dictionary: 'name': 'Max', 'position': 'data scientist', 'level': 'junior';
  2. To the existing dictionary, append a new key named experience (as a string) with the value of 1.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Section 2. Chapter 4
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
some-alt