In your code, def SayHello is not indented (and must be)
this is a difficult code to write interactively, a better example (using a script file) below (includes a default greeting)
MyClass.py:
this is a difficult code to write interactively, a better example (using a script file) below (includes a default greeting)
MyClass.py:
class MyClass: def __init__(self, greeting='there'): self.greeting = greeting def say_hello(self): print(f"Hello {self.greeting}") def main(): myinstance = MyClass() myinstance.say_hello() myinstance.greeting = 'Zelda' myinstance.say_hello() if __name__ == '__main__': main()
Output:Hello there
Hello Zelda