Bird
0
0

Find the error in this code:

medium📝 Debug Q6 of 15
Python - Methods and Behavior Definition
Find the error in this code:
class Person:
    def greet():
        print('Hello!')

p = Person()
p.greet()
Aprint statement syntax error
BCannot create instance of Person
CMissing self parameter in greet method
Dgreet method should be static
Step-by-Step Solution
Solution:
  1. Step 1: Check method definition

    Method greet lacks 'self' parameter, but is called on instance p.
  2. Step 2: Understand method call requirements

    Instance methods must have 'self' as first parameter to receive the instance.
  3. Final Answer:

    Missing self parameter in greet method -> Option C
  4. Quick Check:

    Instance method needs self = A [OK]
Quick Trick: Instance methods always need self parameter [OK]
Common Mistakes:
  • Thinking instance creation fails
  • Assuming print syntax is wrong
  • Confusing instance and static methods

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes