class Person:#set name of class to call it def__init__(self, name, age):#func set verself.name = name#set nameself.age = age#set agedefmyfunc(self):#func inside of class print("Hello my name is "+self.name)# code that the func dose
p1 =Person("barry", 50)# setting a ver fo rthe class
p1.myfunc() #call the func and whitch ver you want it to be with
Posted by: Guest
on June-12-2020
2
class python 3
A class is a block of code that holds various functions. Because they
are located inside a class they are named methods but mean the samne
thing. In addition variables that are stored inside a class are named
attributes. The point of a class is to call the class later allowing you
to access as many functions or (methods) as you would like with the same
class name. These methods are grouped together under one class name due
to them working in association with eachother in some way.#example# To create a simple class:class Shape:
def__init__():
print("A new shape has been created!")
pass
defget_area(self):
pass
# To create a class that uses inheritance and polymorphism# from another class:classRectangle(Shape):
def__init__(self, height, width): # The constructor
super.__init__()
self.height = height
self.width = width
defget_area(self):
returnself.height *self.width
Posted by: Guest
on September-22-2020
Code answers related to "how to add object to class variable python"
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems
resetting your password contact us
Check Your Email and Click on the link sent to your email