Python Online Quiz – It’s exam time for python aspirants

Searching for a good quiz to test your Python knowledge? Your search ends here. This Python online quiz is for intermediate and advanced learners. It will not only help you to test your knowledge but also discover your strengths and weaknesses with Python. I hope you have played the previous quizzes by DataFlair:

So, let’s play the Python online quiz.

Q.1. What is the output of this code?

def func - python online quiz
Correct! Wrong!

We can pass the keyword arguments to func in any order. And ** is evaluated right to left. So, 2**2**4 is 2**16. This is 65536.

Q.2. How will you not create a dictionary?

Correct! Wrong!

Option D creates a set, not a dictionary.

Q.3. In the following code, how will you get to the value 7?

list - python online quiz
Correct! Wrong!

Q.4. Which of these can you use as a dictionary key?

Please select 3 correct answers

Correct! Wrong!

Immutable objects cannot be keys in a dictionary.

Q.5. What does the following code print?

a= 1 2 3 - Python Online Quiz
Correct! Wrong!

a is not the same as a[:] for a list. They refer to different objects.

Q.6. In the following code, what is the output?

Correct! Wrong!

2 and 3 are non-Boolean operands. The and operator gives the second value because both are truthy.

Q.7. Which of the following return True for a string?

Please select 3 correct answers

Correct! Wrong!

s[:] is a reference to the original string, but s[::-1][::-1] is a reference to a new object.

Q.8. What is the value of round(12.5) - round(11.5)?

Correct! Wrong!

Python uses the round-half-to-even strategy. So, round(12.5) and round(11.5) are 12.

Q.9. Select the correct statements:

I. We define classes and functions with the def keyword
II. A class can define an object
III. A class can define a function
IV. A function can define a class

Correct! Wrong!

We define classes with the class keyword and functions with the def keyword. Classes can define functions and objects. Functions can define classes.

Q.10. Select the correct output for this code:

try - python online quiz
Correct! Wrong!

Q.11. What is the output of this code?

print l1 l2 l3 l4 - Python Online Quiz
Correct! Wrong!

l2 is the same object as l1. l3 and l4 are shallow copies of l1. But changing l1 does not change l3 and l4.

Q.12. What is the output of this code?

print l1 l2 - python online quiz
Correct! Wrong!

When we change a sublist in the shallow copy, it changes the original.

Q.13. What is the size of an empty tuple in Python?

Correct! Wrong!

Empty tuples have 48 bytes as overhead size. Also, each element holds 8 bytes.

Q.14. What is the output of this code?

def show - python online quiz
Correct! Wrong!

The program prints for indices 4 to -5, and then raises an IndexError for length=-5.

Python Interview Questions

This completes our third Python online quiz of the series. I hope you enjoyed playing the quiz.

Thinking what next? Check out:

If you have any suggestions regarding the Python online quiz, share it in the comments. We will be glad to update them.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.