SlideShare a Scribd company logo
DATA TYPES IN PYTHON
STUDENT PREPARATION/ HOTHYFA AHMED ALFKEEH
D. E/Auad Almuhalfi
DATA TYPES IN PYTHON
Text Type: str
Numeric Types: int, float, complex
Sequence Types: list, tuple, range
Mapping Type: dict
Set Types: set, frozenset
Boolean Type: bool
Binary Types: bytes, bytearray, memoryview
Python Numbers
There are three numeric types in Python:
int,float,complex
Variables of numeric types are created when you assign a value to
them:
x = 1 # int
y = 2.8 # float
z = 1j # complex
To verify the type of any object in Python, use the type() function:
Example. RESULT.
print(type(x)) <class 'int'>
print(type(y)) <class 'float'>
print(type(z)) <class 'complex'>
Int
Int, or integer, is a whole number, positive or negative, without
decimals, of unlimited length.
Float
Float, or "floating point number" is a number, positive or
negative, containing one or more decimals.
Complex
Complex numbers are written with a "j" as the imaginary par
Type Conversion
You can convert from one type to another with the int(), float(), and
complex() and str() methods:
Example
Convert from one type to another:
x = 1 # int
y = 2.8 # float
z = 1j # complex
#convert from int to float:
a = float(x) #convert from float to int:
b = int(y) #convert from int to complex:
c = complex(x) print(a) print(b) print(c)
print(type(a)) print(type(b)) print(type(c))
Python Strings
String Literals
String literals in python are surrounded by either single quotation
marks, or double quotation marks.
'hello' is the same as "hello".
You can display a string literal with the print() function:
Multiline Strings
You can assign a multiline string to a variable by using three
quotes:
a = """Python is a programming language.
Python can be used on a server to create web applications..
"""
print(a)
Strings are Arrays
Like many other popular programming languages, strings in
Python are arrays of bytes representing unicode characters.
However, Python does not have a character data type, a single
character is simply a string with a length of 1.
Square brackets can be used to access elements of the string.
Get the character at position 1 (remember that the first character
has the position 0):
Example
a = "Hello, World!"
print(a[1])
Slicing
You can return a range of characters by using the slice syntax.
Specify the start index and the end index, separated by a colon,
to return a part of the string.
Get the characters from position 2 to position 5 (not included):
Example. Result.
b = "Hello, World!" llo
print(b[2:5])
String Length
To get the length of a string, use the len() function.
a = "Hello, World!"
print(len(a))
The lower() method returns the string in lower case:
a = "Hello, World!"
print(a.lower())
The upper() method returns the string in upper case:
a = "Hello, World!"
print(a.upper())
The replace() method replaces a string with another string:
a = "Hello, World!"
print(a.replace("H", "J"))
Python Lists
Python Collections (Arrays)
There are four collection data types in the Python programming
language:
List is a collection which is ordered and changeable. Allows
duplicate members.
Tuple is a collection which is ordered and unchangeable. Allows
duplicate members.
Set is a collection which is unordered and unindexed. No
duplicate members.
Dictionary is a collection which is unordered, changeable and
indexed. No duplicate members.
List
A list is a collection which is ordered and changeable. In Python
lists are written with square brackets.
Create a List:
thislist = ["apple", "banana", "cherry"]
print(thislist)
Access Items
You access the list items by referring to the index number:
thislist = ["apple", "banana", "cherry"]
print(thislist[1])
Range of Indexes
You can specify a range of indexes by specifying where to start
and where to end the range.
Return the third, fourth, and fifth item:
thislist = ["apple", "banana", "cherry", "orange", "kiwi", "melon",
"mango"]
print(thislist[2:5])
This example returns the items from the beginning to "orange":
thislist = ["apple", "banana", "cherry", "orange", "kiwi", "melon",
"mango"]
print(thislist[:4])
This example returns the items from "cherry" and to the end:
thislist = ["apple", "banana", "cherry", "orange", "kiwi", "melon",
"mango"]
print(thislist[2:])
Using the append() method to append an item:
thislist = ["apple", "banana", "cherry"]
thislist.append("orange")
print(thislist)
Insert an item as the second position:
thislist = ["apple", "banana", "cherry"]
thislist.insert(1, "orange")
print(thislist)
The remove() method removes the specified item:
thislist = ["apple", "banana", "cherry"]
thislist.remove("banana")
print(thislist)
The pop() method removes the specified index, (or the last item if
index is not specified):
thislist = ["apple", "banana", "cherry"]
thislist.pop()
print(thislist)
The del keyword removes the specified index:
thislist = ["apple", "banana", "cherry"]
del thislist[0]
print(thislist)
Tuple
A tuple is a collection which is ordered and unchangeable. In
Python tuples are written with round brackets.
Create a Tuple:
thistuple = ("apple", "banana", "cherry")
print(thistuple)
Access Tuple Items
You can access tuple items by referring to the index number,
inside square brackets:
Print the second item in the tuple:
thistuple = ("apple", "banana", "cherry")
print(thistuple[1])
Range of Indexes
You can specify a range of indexes by specifying where to start
and where to end the range.
When specifying a range, the return value will be a new tuple
with the specified items.
Return the third, fourth, and fifth item:
thistuple = ("apple", "banana", "cherry", "orange", "kiwi", "melon",
"mango")
print(thistuple[2:5])
Change Tuple Values
Once a tuple is created, you cannot change its values. Tuples are
unchangeable, or immutable as it also is called.
But there is a workaround. You can convert the tuple into a list,
change the list, and convert the list back into a tuple.
Convert the tuple into a list to be able to change it:
x = ("apple", "banana", "cherry")
y = list(x)
y[1] = "kiwi"
x = tuple(y)
print(x)
Result:
("apple", "kiwi", "cherry")
Set
A set is a collection which is unordered and unindexed. In Python
sets are written with curly brackets.
Create a Set:
thisset = {"apple", "banana", "cherry"}
print(thisset)
Access Items
You cannot access items in a set by referring to an index, since
sets are unordered the items has no index.
But you can loop through the set items using a for loop, or ask if
a specified value is present in a set, by using the in keyword.
Loop through the set, and print the values:
thisset = {"apple", "banana", "cherry"}
for x in thisset:
print(x)
Result: banana
cherry
apple
Change Items
Once a set is created, you cannot change its items, but you can
add new items.
Add Items
To add one item to a set use the add() method.
To add more than one item to a set use the update() method.
Add an item to a set, using the add() method:
thisset = {"apple", "banana", "cherry"}
thisset.add("orange")
print(thisset)
Result:
{'orange', 'banana', 'apple', 'cherry'}
Add multiple items to a set, using the update() method:
thisset = {"apple", "banana", "cherry"}
thisset.update(["orange", "mango", "grapes"])
print(thisset)
Result:
{'mango', 'banana', 'apple', 'cherry', 'grapes', 'orange'}
Remove Item
To remove an item in a set, use the remove(), or the discard()
method.
Remove "banana" by using the remove() method:
thisset = {"apple", "banana", "cherry"}
thisset.remove("banana")
print(thisset)
Remove "banana" by using the discard() method:
thisset = {"apple", "banana", "cherry"}
thisset.discard("banana")
print(thisset)
The clear() method empties the set:
thisset = {"apple", "banana", "cherry"}
thisset.clear()
print(thisset)
Result:
set()
The del keyword will delete the set completely:
thisset = {"apple", "banana", "cherry"}
del thisset
print(thisset)
Dictionary
A dictionary is a collection which is unordered, changeable and
indexed. In Python dictionaries are written with curly brackets,
and they have keys and values.
Create and print a dictionary:
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
print(thisdict)
Result:
{'brand': 'Ford', 'model': 'Mustang', 'year': 1964}
Accessing Items
You can access the items of a dictionary by referring to its key
name, inside square brackets:
Get the value of the "model" key:
x = thisdict["model"]
Result:
Mustang
There is also a method called get() that will give you the same
result:
Get the value of the "model" key:
x = thisdict.get("model")
Result:
Mustang
Change Values
You can change the value of a specific item by referring to its key
name:
Change the "year" to 2018:
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
thisdict["year"] = 2018
Result:
{'brand': 'Ford', 'model': 'Mustang', 'year': 2018}
Loop Through a Dictionary
You can loop through a dictionary by using a for loop.
When looping through a dictionary, the return value are the keys
of the dictionary, but there are methods to return the values as
well.
Print all key names in the dictionary, one by one:
for x in thisdict:
print(x)
Result:
brand
model
year
Adding Items
Adding an item to the dictionary is done by using a new index
key and assigning a value to it:
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
thisdict["color"] = "red"
print(thisdict)
Result:
{'brand': 'Ford', 'model': 'Mustang', 'year': 1964, 'color': 'red'}
Removing Items
There are several methods to remove items from a dictionary:
The pop() method removes the item with the specified key name:
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
thisdict.pop("model")
print(thisdict)
Result:
{'brand': 'Ford', 'year': 1964}
The popitem() method removes the last inserted item (in versions
before 3.7, a random item is removed instead):
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
thisdict.popitem()
print(thisdict)
Result:
{'brand': 'Ford', 'model': 'Mustang'}
The del keyword removes the item with the specified key name:
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
del thisdict["model"]
print(thisdict)
Result:
{'brand': 'Ford', 'year': 1964}
The clear() keyword empties the dictionary:
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
thisdict.clear()
print(thisdict)
Result:
{}
Nested Dictionaries
A dictionary can also contain many dictionaries, this is called
nested dictionaries.
Create a dictionary that contain three dictionaries:
myfamily = {"child1" : {
"name" : "Emil",
"year" : 2004
},"child2" : {
"name" : "Tobias",
"year" : 2007
},"child3" : {
"name" : "Linus",
"year" : 2011}}
THANK YOU

More Related Content

PPTX
Python- Basic. pptx with lists, tuples dictionaries and data types
PPTX
Python- Basic.pptx with data types, lists, and tuples with dictionary
PPTX
Chapter 3-Data structure in python programming.pptx
PPTX
cover every basics of python with this..
PPTX
Week 10.pptx
PPTX
PDF
Python Data Types (1).pdf
PDF
Python Data Types.pdf
Python- Basic. pptx with lists, tuples dictionaries and data types
Python- Basic.pptx with data types, lists, and tuples with dictionary
Chapter 3-Data structure in python programming.pptx
cover every basics of python with this..
Week 10.pptx
Python Data Types (1).pdf
Python Data Types.pdf

Similar to Data Type In Python.pptx (20)

PPTX
Python-Basics.pptx
PPT
ComandosDePython_ComponentesBasicosImpl.ppt
PPTX
Python Lists.pptx
PDF
ppt_pspp.pdf
PPTX
UNIT-3 python and data structure alo.pptx
PDF
Python Variable Types, List, Tuple, Dictionary
PDF
Python - Lecture 3
PPTX
In Python, a list is a built-in dynamic sized array. We can store all types o...
PDF
Programming in python Unit-1 Part-1
PPTX
LIST_tuple.pptx
PDF
Datatypes in python
PPTX
Python Lists is a a evry jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...
PDF
"Automata Basics and Python Applications"
PPTX
Python Workshop
PPTX
Python Programming for basic beginners.pptx
PPTX
1-Object and Data Structures.pptx
PPT
01-Python-Basics.ppt
PPT
Python Programming Basic , introductions
PPTX
Basic data structures in python
PPTX
Tuples-and-Dictionaries.pptx
Python-Basics.pptx
ComandosDePython_ComponentesBasicosImpl.ppt
Python Lists.pptx
ppt_pspp.pdf
UNIT-3 python and data structure alo.pptx
Python Variable Types, List, Tuple, Dictionary
Python - Lecture 3
In Python, a list is a built-in dynamic sized array. We can store all types o...
Programming in python Unit-1 Part-1
LIST_tuple.pptx
Datatypes in python
Python Lists is a a evry jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...
"Automata Basics and Python Applications"
Python Workshop
Python Programming for basic beginners.pptx
1-Object and Data Structures.pptx
01-Python-Basics.ppt
Python Programming Basic , introductions
Basic data structures in python
Tuples-and-Dictionaries.pptx
Ad

Recently uploaded (20)

PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Classroom Observation Tools for Teachers
PPTX
GDM (1) (1).pptx small presentation for students
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Pre independence Education in Inndia.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Complications of Minimal Access Surgery at WLH
PDF
Insiders guide to clinical Medicine.pdf
PDF
Sports Quiz easy sports quiz sports quiz
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
STATICS OF THE RIGID BODIES Hibbelers.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Classroom Observation Tools for Teachers
GDM (1) (1).pptx small presentation for students
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Microbial disease of the cardiovascular and lymphatic systems
Pre independence Education in Inndia.pdf
human mycosis Human fungal infections are called human mycosis..pptx
Microbial diseases, their pathogenesis and prophylaxis
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Complications of Minimal Access Surgery at WLH
Insiders guide to clinical Medicine.pdf
Sports Quiz easy sports quiz sports quiz
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Ad

Data Type In Python.pptx

  • 1. DATA TYPES IN PYTHON STUDENT PREPARATION/ HOTHYFA AHMED ALFKEEH D. E/Auad Almuhalfi
  • 2. DATA TYPES IN PYTHON Text Type: str Numeric Types: int, float, complex Sequence Types: list, tuple, range Mapping Type: dict Set Types: set, frozenset Boolean Type: bool Binary Types: bytes, bytearray, memoryview
  • 3. Python Numbers There are three numeric types in Python: int,float,complex Variables of numeric types are created when you assign a value to them: x = 1 # int y = 2.8 # float z = 1j # complex
  • 4. To verify the type of any object in Python, use the type() function: Example. RESULT. print(type(x)) <class 'int'> print(type(y)) <class 'float'> print(type(z)) <class 'complex'> Int Int, or integer, is a whole number, positive or negative, without decimals, of unlimited length. Float Float, or "floating point number" is a number, positive or negative, containing one or more decimals. Complex Complex numbers are written with a "j" as the imaginary par
  • 5. Type Conversion You can convert from one type to another with the int(), float(), and complex() and str() methods: Example Convert from one type to another: x = 1 # int y = 2.8 # float z = 1j # complex #convert from int to float: a = float(x) #convert from float to int: b = int(y) #convert from int to complex: c = complex(x) print(a) print(b) print(c) print(type(a)) print(type(b)) print(type(c))
  • 6. Python Strings String Literals String literals in python are surrounded by either single quotation marks, or double quotation marks. 'hello' is the same as "hello". You can display a string literal with the print() function:
  • 7. Multiline Strings You can assign a multiline string to a variable by using three quotes: a = """Python is a programming language. Python can be used on a server to create web applications.. """ print(a) Strings are Arrays Like many other popular programming languages, strings in Python are arrays of bytes representing unicode characters. However, Python does not have a character data type, a single character is simply a string with a length of 1. Square brackets can be used to access elements of the string.
  • 8. Get the character at position 1 (remember that the first character has the position 0): Example a = "Hello, World!" print(a[1]) Slicing You can return a range of characters by using the slice syntax. Specify the start index and the end index, separated by a colon, to return a part of the string. Get the characters from position 2 to position 5 (not included): Example. Result. b = "Hello, World!" llo print(b[2:5])
  • 9. String Length To get the length of a string, use the len() function. a = "Hello, World!" print(len(a)) The lower() method returns the string in lower case: a = "Hello, World!" print(a.lower()) The upper() method returns the string in upper case: a = "Hello, World!" print(a.upper()) The replace() method replaces a string with another string: a = "Hello, World!" print(a.replace("H", "J"))
  • 10. Python Lists Python Collections (Arrays) There are four collection data types in the Python programming language: List is a collection which is ordered and changeable. Allows duplicate members. Tuple is a collection which is ordered and unchangeable. Allows duplicate members. Set is a collection which is unordered and unindexed. No duplicate members. Dictionary is a collection which is unordered, changeable and indexed. No duplicate members.
  • 11. List A list is a collection which is ordered and changeable. In Python lists are written with square brackets. Create a List: thislist = ["apple", "banana", "cherry"] print(thislist) Access Items You access the list items by referring to the index number: thislist = ["apple", "banana", "cherry"] print(thislist[1]) Range of Indexes You can specify a range of indexes by specifying where to start and where to end the range.
  • 12. Return the third, fourth, and fifth item: thislist = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"] print(thislist[2:5]) This example returns the items from the beginning to "orange": thislist = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"] print(thislist[:4]) This example returns the items from "cherry" and to the end: thislist = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"] print(thislist[2:])
  • 13. Using the append() method to append an item: thislist = ["apple", "banana", "cherry"] thislist.append("orange") print(thislist) Insert an item as the second position: thislist = ["apple", "banana", "cherry"] thislist.insert(1, "orange") print(thislist) The remove() method removes the specified item: thislist = ["apple", "banana", "cherry"] thislist.remove("banana") print(thislist)
  • 14. The pop() method removes the specified index, (or the last item if index is not specified): thislist = ["apple", "banana", "cherry"] thislist.pop() print(thislist) The del keyword removes the specified index: thislist = ["apple", "banana", "cherry"] del thislist[0] print(thislist)
  • 15. Tuple A tuple is a collection which is ordered and unchangeable. In Python tuples are written with round brackets. Create a Tuple: thistuple = ("apple", "banana", "cherry") print(thistuple) Access Tuple Items You can access tuple items by referring to the index number, inside square brackets: Print the second item in the tuple: thistuple = ("apple", "banana", "cherry") print(thistuple[1])
  • 16. Range of Indexes You can specify a range of indexes by specifying where to start and where to end the range. When specifying a range, the return value will be a new tuple with the specified items. Return the third, fourth, and fifth item: thistuple = ("apple", "banana", "cherry", "orange", "kiwi", "melon", "mango") print(thistuple[2:5]) Change Tuple Values Once a tuple is created, you cannot change its values. Tuples are unchangeable, or immutable as it also is called. But there is a workaround. You can convert the tuple into a list, change the list, and convert the list back into a tuple.
  • 17. Convert the tuple into a list to be able to change it: x = ("apple", "banana", "cherry") y = list(x) y[1] = "kiwi" x = tuple(y) print(x) Result: ("apple", "kiwi", "cherry")
  • 18. Set A set is a collection which is unordered and unindexed. In Python sets are written with curly brackets. Create a Set: thisset = {"apple", "banana", "cherry"} print(thisset) Access Items You cannot access items in a set by referring to an index, since sets are unordered the items has no index. But you can loop through the set items using a for loop, or ask if a specified value is present in a set, by using the in keyword.
  • 19. Loop through the set, and print the values: thisset = {"apple", "banana", "cherry"} for x in thisset: print(x) Result: banana cherry apple Change Items Once a set is created, you cannot change its items, but you can add new items. Add Items To add one item to a set use the add() method. To add more than one item to a set use the update() method.
  • 20. Add an item to a set, using the add() method: thisset = {"apple", "banana", "cherry"} thisset.add("orange") print(thisset) Result: {'orange', 'banana', 'apple', 'cherry'} Add multiple items to a set, using the update() method: thisset = {"apple", "banana", "cherry"} thisset.update(["orange", "mango", "grapes"]) print(thisset) Result: {'mango', 'banana', 'apple', 'cherry', 'grapes', 'orange'}
  • 21. Remove Item To remove an item in a set, use the remove(), or the discard() method. Remove "banana" by using the remove() method: thisset = {"apple", "banana", "cherry"} thisset.remove("banana") print(thisset) Remove "banana" by using the discard() method: thisset = {"apple", "banana", "cherry"} thisset.discard("banana") print(thisset)
  • 22. The clear() method empties the set: thisset = {"apple", "banana", "cherry"} thisset.clear() print(thisset) Result: set() The del keyword will delete the set completely: thisset = {"apple", "banana", "cherry"} del thisset print(thisset)
  • 23. Dictionary A dictionary is a collection which is unordered, changeable and indexed. In Python dictionaries are written with curly brackets, and they have keys and values. Create and print a dictionary: thisdict = { "brand": "Ford", "model": "Mustang", "year": 1964 } print(thisdict) Result: {'brand': 'Ford', 'model': 'Mustang', 'year': 1964}
  • 24. Accessing Items You can access the items of a dictionary by referring to its key name, inside square brackets: Get the value of the "model" key: x = thisdict["model"] Result: Mustang There is also a method called get() that will give you the same result: Get the value of the "model" key: x = thisdict.get("model") Result: Mustang
  • 25. Change Values You can change the value of a specific item by referring to its key name: Change the "year" to 2018: thisdict = { "brand": "Ford", "model": "Mustang", "year": 1964 } thisdict["year"] = 2018 Result: {'brand': 'Ford', 'model': 'Mustang', 'year': 2018}
  • 26. Loop Through a Dictionary You can loop through a dictionary by using a for loop. When looping through a dictionary, the return value are the keys of the dictionary, but there are methods to return the values as well. Print all key names in the dictionary, one by one: for x in thisdict: print(x) Result: brand model year
  • 27. Adding Items Adding an item to the dictionary is done by using a new index key and assigning a value to it: thisdict = { "brand": "Ford", "model": "Mustang", "year": 1964 } thisdict["color"] = "red" print(thisdict) Result: {'brand': 'Ford', 'model': 'Mustang', 'year': 1964, 'color': 'red'}
  • 28. Removing Items There are several methods to remove items from a dictionary: The pop() method removes the item with the specified key name: thisdict = { "brand": "Ford", "model": "Mustang", "year": 1964 } thisdict.pop("model") print(thisdict) Result: {'brand': 'Ford', 'year': 1964}
  • 29. The popitem() method removes the last inserted item (in versions before 3.7, a random item is removed instead): thisdict = { "brand": "Ford", "model": "Mustang", "year": 1964 } thisdict.popitem() print(thisdict) Result: {'brand': 'Ford', 'model': 'Mustang'}
  • 30. The del keyword removes the item with the specified key name: thisdict = { "brand": "Ford", "model": "Mustang", "year": 1964 } del thisdict["model"] print(thisdict) Result: {'brand': 'Ford', 'year': 1964}
  • 31. The clear() keyword empties the dictionary: thisdict = { "brand": "Ford", "model": "Mustang", "year": 1964 } thisdict.clear() print(thisdict) Result: {}
  • 32. Nested Dictionaries A dictionary can also contain many dictionaries, this is called nested dictionaries. Create a dictionary that contain three dictionaries: myfamily = {"child1" : { "name" : "Emil", "year" : 2004 },"child2" : { "name" : "Tobias", "year" : 2007 },"child3" : { "name" : "Linus", "year" : 2011}}