WorksheetsPython Programming Quiz
Total questions: 30
Worksheet time: 15mins
Which of the following is a correct way to declare a variable in Python?
var = 10
10 = var
var == 10
10 var =
What is the output of print(2 ** 3)?
8
6
9
7
Which method is used to find the length of a list in Python?
len()
length()
size()
count()
How do you add an element x to a list my_list in Python?
my_list.append(x)
my_list.add(x)
my_list.insert(x)
my_list.addElement(x)
What is the result of the expression 5 // 2?
2.5
3
2
2.0
What will be the output of print("Hello" * 3)?
HelloHelloHello
Hello 3
HelloHello 3
3Hello
Which function is used to take input from the user in Python?
input()
read()
get()
scan()
How do you write a single-line comment in Python?
/* This is a comment */
// This is a comment
# This is a comment
-- This is a comment
Which of the following is used to handle exceptions in Python?
try-except
if-else
for-else
do-while
Which of the following is a valid string declaration in Python?
str = "Hello"
str = 'Hello"
str = Hello
str = """Hello"""
What will be the output of print(type([1, 2, 3]))?
How can you check the type of a variable x in Python?
type(x)
typeof(x)
check(x)
var_type(x)
Which of the following is the correct syntax to define a function in Python?
def my_function()
function my_function()
define my_function()
function = my_function()
What does len() return when applied to a dictionary?
The number of keys in the dictionary
The number of values in the dictionary
The number of key-value pairs in the dictionary
It raises an error
How can you remove an item from a dictionary by its key?
del dict[key]
dict.remove(key)
dict.pop(key)
Both a and c
What will print(3 == 3) output?
True
False
None
Error
What will be the result of print(5 != 5)?
True
False
None
Error
How would you create a set in Python?
set = {1, 2, 3}
set = (1, 2, 3)
set = [1, 2, 3]
set =
Which Python keyword is used to define a class?
def
class
function
object
Which method is used to add an element to a set in Python?
set.add()
set.insert()
set.append()
set.appendElement()
How do you iterate over a list my_list in Python?
for i in my_list:
for (i: my_list)
for i from my_list:
foreach i in my_list:
How would you find the maximum number from a list numbers = [2, 3, 1, 7, 5]?
max(numbers)
maximum(numbers)
find_max(numbers)
numbers.max()
Which function can be used to sort a list my_list in ascending order?
sort()
order()
arrange()
sortList()
How do you check if a key exists in a dictionary my_dict?
my_dict.contains(key)
key in my_dict
my_dict.exists(key)
my_dict.key(key)
What is the output of print("python"[2:5])?
tho
pyth
thon
t
Which of the following operators is used for floor division in Python?
/
%
//
^
Which of the following is used to return the remainder of a division?
//
/
%
divmod()
How do you check the length of a string in Python?
str.length()
length(str)
len(str)
size(str)
What is the result of print(4 + 2 * 3)?
12
10
8
6
Which of the following will raise an error in Python?
a = "hello"
x = 3.5 + 2
print(2 + "3")
y = [1, 2, 3]
