Answers for "making functions in calsses python"

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
3

how to define a function in python

def function_name():
  pass
Posted by: Guest on March-10-2020
3

how to define functions in python

def add(number):
  equation = 5 + number
  print(equation)
  
 
add(10)

output:
  
  15
Posted by: Guest on September-20-2020

Python Answers by Framework

Browse Popular Code Answers by Language