Python Quiz

Are you ready to test your Python skills? Whether you’re a beginner brushing up on the basics or an experienced developer, a Python quiz is a great way to assess your knowledge and learn new things. At The Coding College, we’ve designed a quiz to challenge and grow your Python programming expertise.

Why Take a Python Quiz?

Taking quizzes helps you:

  • Evaluate Your Knowledge: Identify strengths and areas for improvement.
  • Reinforce Learning: Quizzes engage your memory and enhance retention.
  • Prepare for Interviews: Practice Python concepts frequently asked during coding interviews.

Python Quiz: Test Your Skills

Beginner-Level Questions

1. What is the output of the following code?

print(2 * 3 + 4)  
  • A) 14
  • B) 10
  • C) 12
  • D) Error

2. Which of the following is the correct way to create a variable in Python?

  • A) var 1 = 10
  • B) 1_var = 10
  • C) var1 = 10
  • D) var-1 = 10

3. What does the len() function do in Python?

  • A) Returns the last element of a list
  • B) Calculates the sum of elements in a list
  • C) Returns the length of an object
  • D) Deletes the last element of a list

Intermediate-Level Questions

4. What is the output of the following code?

def add(x, y=2):  
    return x + y  

print(add(5))  
  • A) 5
  • B) 7
  • C) Error
  • D) None

5. How do you convert a string "123" into an integer?

  • A) int("123")
  • B) str(123)
  • C) float("123")
  • D) list("123")

6. Which keyword is used to handle exceptions in Python?

  • A) try
  • B) catch
  • C) throw
  • D) except

Advanced-Level Questions

7. What is the output of the following code?

a = [1, 2, 3]  
b = a  
b[0] = 10  
print(a)  
  • A) [10, 2, 3]
  • B) [1, 2, 3]
  • C) Error
  • D) None

8. Which of the following is a Python set operation?

  • A) union()
  • B) intersection()
  • C) difference()
  • D) All of the above

9. How do you define a class in Python?

  • A) function ClassName:
  • B) def ClassName:
  • C) class ClassName:
  • D) object ClassName:

Python Quiz Answers

Beginner-Level

  1. B) 10
    Explanation: Multiplication takes precedence over addition.
  2. C) var1 = 10
    Explanation: Variable names must not start with a number or include special characters like -.
  3. C) Returns the length of an object

Intermediate-Level

  1. B) 7
    Explanation: The function uses the default value of y=2 when only one argument is passed.
  2. A) int(“123”)
  3. D) except

Advanced-Level

  1. A) [10, 2, 3]
    Explanation: Both a and b point to the same list in memory, so changing b affects a.
  2. D) All of the above
  3. C) class ClassName:

Take More Quizzes

Want to explore more quizzes and challenges? Check out our Python tutorials and exercises at The Coding College.

Level Up Your Python Skills Today!
Quizzes are an excellent way to track your progress. Take the next step and dive deeper into Python programming with The Coding College.

Leave a Comment