Quiz M3. Data Types
Quiz M3. Data Types
2. What is the name of the tool used in the Python code below?
New_list – [expression for item in iterable if condition]
Generators
Comprehensions
Shorted loops
4. What is the difference between accessing dictionary elements using “[]” and get()?
There is no difference. It depends on your preferences.
Get() returns the value by key without raising an error if the key doesn’t exist.
“[]” is safer than get().
5. What is the correct definition of the update() built-in method for set data type?
The method updates set elements to the intersection with the given sets.
The method updates set elements to the difference with the given sets.
The method updates set elements to the union with the given sets.
The method is used to add a new element to a set.
6. Which operator is used to compare objects id in Python?
Is
And
==
7. Which of the answers describes the behavior of the following code in Python correctly?
my_list = [1, 2]
Print(id(my_list))
23456
my_list.append(3)
Print(id(my_list))
23456
An iterable object which consists of integers will not change its id if appended only by
integers.
If we append only one value to the list, it will not change its id.
Some objects can be changed after creation but will keep the first-time assigned id. It is
called mutable objects.
12. which of these are true about the set data type in Python?
Set elements are ordered
A set is mutable
A set is dynamic like a list
Set elements can be of any hashable type
A set can not contain duplicate elements
13. Choose the correct statements about the dictionary data type in Python.
A dictionary can not contain other dictionaries.
A dictionary is an associative array with arbitrary keys mapped to values.
A dictionary is mutable and dynamic, it can grow and shrink.