Python Objective Quiz

Test your knowledge in the basics of Python
Author

Juma Shafara

Published

February 1, 2024

Keywords

python, python quiz, python data types, python functions

Photo by DATAIDEA

Test your knowledge in the basics of Python

Question 1: What is the output of the following code?

print(type([]) is list)
  1. True
  2. False
  3. Error
  4. None
Reveal answer

a.True


Question 2: Which of the following is not a valid Python data type?

  1. list
  2. tuple
  3. dictionary
  4. array
Reveal answer

d.array


Question 3: What does the len() function do?

  1. Returns the number of characters in a string
  2. Returns the number of items in a list or tuple
  3. Returns the number of key-value pairs in a dictionary
  4. All of the above
Reveal answer

d.All of the above


Question 4: How do you create a set in Python?

  1. my_set = {}
  2. my_set = []
  3. my_set = ()
  4. my_set = set()
Reveal answer

d.my_set = set()


Question 5: What is the output of the following code?

x = "Python"
print(x[0])
  1. P
  2. y
  3. h
  4. 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?

  1. append()
  2. add()
  3. insert()
  4. extend()
Reveal answer

a.append


Question 7: What is the output of the following code?

for i in range(3):
    print(i)
  1. 1 2 3
  2. 0 1 2
  3. 0 1 2 3
  4. 1 2 3 4
Reveal answer

b.0 1 2


Question 8: How do you create a function in Python?

  1. function my_func():
  2. def my_func:
  3. def my_func():
  4. func my_func():
Reveal answer

b.def my_func


Question 9: What will be the output of the following code?

print(2**3)
  1. 6
  2. 8
  3. 9
  4. 11
Reveal answer

b.8


Question 10: Which keyword is used to handle exceptions in Python?

  1. try
  2. catch
  3. except
  4. handle
Reveal answer

c.except

How many did you get? Put it in the comments!

Back to top