Bird
0
0

Which of the following is the correct syntax to define a class named Car?

easy📝 Syntax Q12 of 15
Python - Classes and Object Lifecycle
Which of the following is the correct syntax to define a class named Car?
Aclass Car:
Bclass Car()
Cdef Car():
Dclass Car[]:
Step-by-Step Solution
Solution:
  1. Step 1: Check class header syntax

    Python allows defining a class with or without parentheses if no base class is specified. So class Car: is correct.
  2. Step 2: Identify incorrect options

    def Car(): defines a function, not a class. class Car() is valid syntax but less common; however, it requires a colon at the end. class Car[]: is invalid syntax.
  3. Final Answer:

    class Car: -> Option A
  4. Quick Check:

    Class header ends with colon, no brackets [OK]
Quick Trick: Class header ends with colon, no brackets needed [OK]
Common Mistakes:
  • Using def instead of class
  • Adding square brackets [] in class header
  • Omitting colon at end

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes