Bird
Raised Fist0

Which of the following is the correct syntax to define a class named Person in Python?

easy📝 Syntax Q3 of Q15
Python - Object-Oriented Programming Foundations
Which of the following is the correct syntax to define a class named Person in Python?
Adef Person():
Bclass Person:
Cclass Person()
Dfunction Person:
Step-by-Step Solution
Solution:
  1. Step 1: Recall Python class definition syntax

    In Python, classes are defined using the keyword class followed by the class name and a colon.
  2. Step 2: Check each option

    class Person: uses correct syntax: class Person:. class Person() is incorrect because parentheses are optional but if used must be followed by a colon.
  3. Final Answer:

    class Person: -> Option B
  4. Quick Check:

    Class definition syntax = class ClassName: [OK]
Quick Trick: Define classes with 'class ClassName:' syntax [OK]
Common Mistakes:
MISTAKES
  • Using def instead of class
  • Omitting the colon at the end
  • Using parentheses incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes