** class Class name: **
class MenuItem:
pass
** Variable name = Class () **
menu_item1 = MenuItem()
menu_item1.name = "Fin cutlet"
** Instance. Instance variable name **
print(menu_item1.name)
Output result Fin cutlet
Method call ** Instance. Method name () **
The first argument is self
class MenuItem:
def hello(self):
print("Hello")
menu_item1 = MenuItem()
menu_item1.hello()
Processing can be executed immediately after instantiation
When using the __init__
method
class MenuItem:
def __init__(self , name)
self.name = name
menu_item1 = MenuItem("Fin cutlet")
print(menu_item1.name)
Recommended Posts