Answers for "how to make classes in python 3"

22

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!
Posted by: Guest on November-17-2019
0

creating python classes

class car:
  def __init__(self, model, color):
    self.model = model
    self.color = color
         
tesla = car("model 3", "black")
Posted by: Guest on June-07-2021

Code answers related to "how to make classes in python 3"

Python Answers by Framework

Browse Popular Code Answers by Language