Answers for "class examples python"

3

class python

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

p1 = Person("John", 36)

p1.age = 40

print(p1.age)
---------------------------------------------------------------
40
Posted by: Guest on October-29-2020
0

how to use a class in python

class awwab(object):
    def __init__(self, name, age):
        self.name = name
        self.age = age
    
    def speak(self):
        print("Hello, my name is",self.name,"and I am",self.age,"years old!")
        
awwabasad = awwab("Awwab Asad", 11)
print(awwabasad.speak())
Posted by: Guest on July-31-2021

Python Answers by Framework

Browse Popular Code Answers by Language