Font size
Worksheetsreview python
Total questions: 20
Worksheet time: 13mins
Which of the following is not a valid variable name in Python?
var_1
_var
1var
var$
What will be the result of the following Boolean expression in Python? (3 == 3) or (5 > 10)
True
False
None
Error
What is the output of the following code? x = 3.14 and type(x)
What is the result of the following expression? 5 ** 2
10
25
7
2.5
What will the following code output? my_list = [1, 2, 3], my_list.append(4), and print(my_list)
[1, 2, 3, 4]
[4, 1, 2, 3]
[1, 2, 4]
[1, 4, 2, 3]
What does the following code do? person = {'name': 'John', 'age': 30} and person['age'] = 31
Adds a new key-value pair to the dictionary
Updates the value of the key 'age'
Deletes the key 'age'
Throws an error because the key 'age' already exists
Which of the following operations is allowed on a tuple in Python?
Changing a tuple’s value
Appending an item to a tuple
Concatenating two tuples
Removing an item from a tuple
What is the purpose of the return keyword in a Python function?
To exit the function
To pass values into the function
To return a value from the function
To define a function
Which of the following is the correct way to write a file in Python?
f = open('file.txt', 'r')
f = open('file.txt', 'w')
f = open('file.txt', 'a')
Both B and C
What does the regular expression pattern \w match?
A word character (letters, digits, and underscores)
A non-word character
A whitespace character
A digit
Which of the following is the correct way to declare a variable in Python?
var = 10
int var = 10
10 = var
var := 10
What is the result of the following Boolean expression in Python? (5 > 3) and (2 < 4)
True
False
None
Error
Which of the following is a valid declaration of a string in Python?
string = "Hello"
string = Hello
string = 'Hello'
Both A and C
What is the result of the following expression? 10 % 3
3
1
0
10
Which of the following is the correct way to declare a list in Python?
list = (1, 2, 3)
list = [1, 2, 3]
list = {1, 2, 3}
list = "1, 2, 3"
What is the correct way to access the value associated with the key 'name' in the dictionary person = {'name': 'Alice', 'age': 30} ?
person['name']
person[name]
person.get(name)
Both A and C
Which of the following is an immutable data structure in Python?
List
Dictionary
Set
Tuple
Which of the following is the correct way to define a function in Python?
function myFunc() { }
def myFunc():
def myFunc() { }
function: myFunc()
Which of the following modes is used to open a file for reading in Python?
r+
w
r
a
What does the regular expression pattern \d+ match?
One or more digits
One or more non-digits
Exactly one digit
Exactly one non-digit
