WorksheetsPython Workshop Quiz
Total questions: 15
Worksheet time: 8mins
Which keyword is used to declare a variable in Python?
var
declare
define
none of the above
What is the output of the following code snippet?
my_tuple = ("apple", "banana", "cherry")
print(my_tuple[1])
"banana"
"apple"
"cherry"
TypeError:
'tuple' object has no attribute '1'
Which of the following is NOT a valid data type in Python?
int
float
string
character
What is the output of the following code snippet?
my_list = [1, 2, 3, 4, 5]
print(my_list[1:3])
[1, 2]
[2, 3]
[3, 4]
[1, 2, 3]
How do you check the number of elements in a set in Python?
elements(my_set)
len(my_set)
count(my_set)
size(my_set)
What does the
append()method do in Python?
Removes an element from a list
Adds an element to the start of a list
Adds an element to the end of a list
Reverses the order of elements in a list
How do you remove an item from a list in Python?
discard(item)
delete(item)
pop(item)
remove(item)
What is the output of the following code snippet?
my_list = [1, 2, 3, 4, 5]
print(my_list[-1])
1
2
5
4
Can a tuple be modified after it is created?
Yes, you can add or remove elements from a tuple
No, tuples are immutable and cannot be modified
Only if the tuple contains string elements
Only if the tuple contains numeric elements.
Which operator is used for exponentiation in Python?
**
^
%
*
What is the purpose of the '
pass'statement in Python?
It terminates the program
It raises an exception
It skips the current iteration of a loop
It defines a new function
What is the output of following code snippet?
def Yes():
No()
def No():
Yes()
ans= Yes()
Ans = ("yes")
print (Ans)
Ans
Yes
error
infinte loop
What is the output of the following code snippet?
x = 5
y = 2
result = x // y
print(result)
2.5
2.0
2.5 (with a warning)
2
Which of the following is NOT a valid way to comment a single line of code in Python?
// Comment
# Comment
''' Comment '''
""" Comment """
What is the output of the following code snippet?
my_list = [1, 2, 3, 4, 5]
print(mylist[-1])
1
2
5
none of the above
