Font size
WorksheetsPython Lists and dictionaries revision
Total questions: 40
Worksheet time: 20mins
What are the different data types in Python?
integer, float, string, list, tuple, dictionary, set, and boolean
cat, dog, bird, fish
red, blue, green, yellow
apple, banana, orange, grape
Explain the difference between mutable and immutable data types in Python.
Mutable data types can only be used once, while immutable data types can be reused
Mutable data types are only used for integers, while immutable data types are used for strings
Mutable data types are always larger in size than immutable data types
Mutable data types can be changed after creation, while immutable data types cannot be changed.
Give examples of numeric data types in Python.
dict, set, tuple
int, float, complex
str, bool, list
char, double, real
What is the use of the 'str' data type in Python?
To store and manipulate text
To create loops and conditions
To store images and videos
To perform mathematical operations
How are lists and tuples different in Python?
Lists can be modified after creation, while tuples cannot be modified after creation.
Lists and tuples are the same in Python
Lists and tuples cannot store different data types in Python
Tuples can be modified after creation, while lists cannot be modified after creation
Explain the concept of type conversion in Python.
Type conversion in Python refers to the process of converting lists into dictionaries.
Type conversion in Python refers to the process of converting text into images.
Type conversion in Python refers to the process of converting one data type into another.
Type conversion in Python refers to the process of converting integers into floats.
What is the purpose of the 'bool' data type in Python?
To perform mathematical operations
To store text values
To represent boolean values
To represent date and time values
Discuss the importance of understanding data types in programming.
It has no importance in programming
It only makes the code more complicated
Data types are not relevant in programming
It helps in efficient memory usage, proper data manipulation, and avoiding errors.
How are dictionaries and sets different in Python?
Dictionaries are key-value pairs while sets are unordered collections of unique elements.
Dictionaries are ordered while sets are unordered
Dictionaries can only store integers while sets can store any data type
Dictionaries can have duplicate elements while sets cannot
What are Relational Operators used for in Python?
B. To compare values
D. To validate whether a value is found within a sequence
C. To assign values to variables
A. To perform arithmetic operations like addition, multiplication, division, etc.
How are comments denoted in Python?
A. Using // at the beginning of a line
B. Enclosing text within /* and */
C. Preceding text with # symbol
D. Using around text
How are strings represented in Python?
A. Using single quotes ('') or double quotes ("")
B. Using square brackets []
C. Using curly braces {}
D. Using parentheses ()
What is the purpose of the 'in' keyword in Python?
A. To check if a value is present in a sequence
B. To perform arithmetic operations
C. To define a new variable
D. To compare two strings
What is the purpose of the 'and' keyword in Python?
A. To check if both conditions are true
B. To perform bitwise AND operation
C. To define a new variable
D. To compare two strings
What is the purpose of the 'not' keyword in Python?
A. To negate a boolean value
B. To perform logical OR operation
C. To assign values to variables
D. To compare the memory locations of two objects
What is the purpose of the 'or' keyword in Python?
A. To check if either of the conditions is true
B. To perform bitwise OR operation
C. To define a new variable
D. To compare two strings
How are dictionaries represented in Python?
A. Using single quotes ('') or double quotes ("")
B. Using square brackets []
C. Using curly braces {}
D. Using parentheses ()
What is the purpose of the 'is' keyword in Python?
A. To check if two variables refer to the same object
B. To perform logical OR operation
C. To assign values to variables
D. To compare the memory locations of two objects
How are tuples represented in Python?
A. Using single quotes ('') or double quotes ("")
B. Using square brackets []
C. Using curly braces {}
D. Using parentheses ()
What is the result of the following expression? x = 5 y = 3 z = x + y a) 8 b) 15 c) 53 d) Error
b) 15
c) 53
d) Error
a) 8
Which operator is used for exponentiation in Python?
**
//
*
^
Which operator is used for floor division in Python?
%
*
/
//
Which one is a valid identifier
_count
1count
break
True
Which one is not a valid operator
**
^^
//
*
Python is a general purpose programming language created by
Dennis M. Ritchie
Guido Van Rossum
James Gosling
Bjarne Stroustrup
__________are special words that are used by Python interpreter to recognize the
structure of program.
Tokens
Identifiers
Keywords
Operators
Examples of String Literals
"ABC1273"
nfjdlsj@@$
12638
'7e920938'
________________method will returns number of key-value pairs in the given dictionary.
len( )
pop( )
del( )
keys( )
values( )
Which of the following will give error?
Suppose dict1={"a":1,"b":2,"c":3}
print(len(dict1))
print(dict1.get("b"))
dict1["a"]=5
None of these.
What would be the output of the following code snippet?
a_dict = {'color': 'blue', 'fruit': 'apple', 'pet': 'dog'}
d_items = a_dict.items()
print(d_items)
('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')
dict_items([('color'), ('fruit'), ('pet')])
[('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')]
dict_items([('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')])
What would the output of the program be?
thisList = ["square", "circle", "triangle", "octagon"]
if "triangle" in thisList:
print("Yes, 'triangle' is in the list")
else:
print("No triangle here!")
Yes, 'triangle' is in the list
"No triangle here!"
What will be the output when this code is executed?
1
2
3
4
5
2
4
1 3 5
1
3
5
What is the output of this code?
5 4 3 2 1
5
4
3
2
1
1
2
3
4
5
1 2 3 4 5
What will be the output of the following Python code?
>>> a={3,4,5}
>>> a.update([1,2,3])
>>> a
Error, no method called update for set data type
{1, 2, 3, 4, 5}
Error, list can’t be added to set
Error, duplicate item present in list
What will be the output of the following code? python my_dict = {'a': 1, 'b': 2} my_dict['a'] = my_dict['a'] * 2 print(my_dict['a'])
1
2
3
4
What will be the output of the following code? python my_dict = {'a': 1, 'b': 2} my_dict.clear() print(my_dict)
{}
None
{'a': 1, 'b': 2}
KeyError
In an list, what is the first numbered position in which data can be stored?
Position 0
Position 1
