Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to define a class in python

class Person:
  def __init__(self, name, age):
    self.name = name
    self.age = age

    def say_name(self):
      print(f"Hello, I am {self.name}")

p1 = Person("Sara", 18)
p1.say_name() 
Source by codefreelance.net #
 
PREVIOUS NEXT
Tagged: #define #class #python
ADD COMMENT
Topic
Name
7+1 =