Objective Quiz
title: Python Objective Quiz keywords: [python, python quiz, python data types, python functions] description: Test your knowledge in the basics of Python author: Juma Shafara date: "2024-2"

Test your knowledge in the basics of Python
Question 1: What is the output of the following code?
a) True
b) False
c) Error
d) None
Reveal answer
a.True
Question 2: Which of the following is not a valid Python data type?
a) list
b) tuple
c) dictionary
d) array
Reveal answer
d.array
Question 3: What does the len() function do?
a) Returns the number of characters in a string
b) Returns the number of items in a list or tuple
c) Returns the number of key-value pairs in a dictionary
d) All of the above
Reveal answer
d.All of the above
Question 4: How do you create a set in Python?
a) my_set = {}
b) my_set = []
c) my_set = ()
d) my_set = set()
Reveal answer
d.my_set = set()
Question 5: What is the output of the following code?
a) P
b) y
c) h
d) 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?
a) append()
b) add()
c) insert()
d) extend()
Reveal answer
a.append
Question 7: What is the output of the following code?
a) 1 2 3
b) 0 1 2
c) 0 1 2 3
d) 1 2 3 4
Reveal answer
b.0 1 2
Question 8: How do you create a function in Python?
a) function my_func():
b) def my_func:
c) def my_func():
d) func my_func():
Reveal answer
b.def my_func
Question 9: What will be the output of the following code?
a) 6
b) 8
c) 9
d) 11
Reveal answer
b.8
Question 10: Which keyword is used to handle exceptions in Python?
a) try
b) catch
c) except
d) handle
Reveal answer
c.except