python class oop code example
Example 1: how to make a class in python
class Person:
def __init__(self, _name, _age):
self.name = _name
self.age = _age
def sayHi(self):
print('Hello, my name is ' + self.name + ' and I am ' + self.age + ' years old!')
p1 = Person('Bob', 25)
p1.sayHi() # Prints: Hello, my name is Bob and I am 25 years old!
Example 2: oop in python
class Object:
#__init__() is called when you create an Object class
def __init__(self,arg):
#stores argument in self
self.arg = arg
def printArg(self):
#calls argument from self
print(self.arg)