Python Objective Quiz
Test your knowledge in the basics of Python
Keywords
python, python quiz, python data types, python functions
Test your knowledge in the basics of Python
Question 1: What is the output of the following code?
print(type([]) is list)
True
False
Error
None
Reveal answer
a.True
Question 2: Which of the following is not a valid Python data type?
list
tuple
dictionary
array
Reveal answer
d.array
Question 3: What does the len()
function do?
- Returns the number of characters in a string
- Returns the number of items in a list or tuple
- Returns the number of key-value pairs in a dictionary
- All of the above
Reveal answer
d.All of the above
Question 4: How do you create a set in Python?
my_set = {}
my_set = []
my_set = ()
my_set = set()
Reveal answer
d.my_set = set()
Question 5: What is the output of the following code?
= "Python"
x print(x[0])
P
y
h
n
Reveal answer
a.P
Question 6: Which of the following methods can be used to add an element to the end of a list in Python?
append()
add()
insert()
extend()
Reveal answer
a.append
Question 7: What is the output of the following code?
for i in range(3):
print(i)
1 2 3
0 1 2
0 1 2 3
1 2 3 4
Reveal answer
b.0 1 2
Question 8: How do you create a function in Python?
function my_func():
def my_func:
def my_func():
func my_func():
Reveal answer
b.def my_func
Question 9: What will be the output of the following code?
print(2**3)
6
8
9
11
Reveal answer
b.8
Question 10: Which keyword is used to handle exceptions in Python?
try
catch
except
handle
Reveal answer
c.except