Calling function

This is an assignment. But it don’t work.

class Student:
    def __init__(self, name): = name
    def greet():
        print(" says hi")

obj = Student("John")

It is to output “John say hi”

I found the answer!!! one line needed to define self. def greet(self): The self was missing.

Do you think I will forget this? NO. LOL

Oh, I beg to differ. I have been programming in Python for years, I have a snazzy Python-aware editor which automatically completes what I type, and I still make this mistake.

Welcome to Python! :wink:

Also greet() is a method so you need to call it a different way:

a) obj.greet() - The normal way of calling methods.
b) Student.greet(obj) - This way is normally used in different cases - when you need to get the function object (Student.greet).