A class is a template of code and collection of objects that has same set of attributes and
behaviour. To create a class use the keyword class followed by class name beginning with an uppercase letter.
A company belongs to class called company class and can have the attributes say first-name and last-name and behaviour methods say showFullName().
Ex :
class Person(): #method
def inputName(self,fname,lname): self.fname=fname self.lastname=lastname
#method
def showFullName() (self):
print(self.fname+" "+self.lname)person1 = Person() #object instantiation person1.inputName
("Mindstick","Software") #calling a method inputName person1. showFullName() #calling a method
showFullName()
you can define a method inside a class the first argument to the method must be self where self –
is a pointer to the class instance. self must be passed as an argument to the method, though the method does not take any arguments.
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
A class is a template of code and collection of objects that has same set of attributes and behaviour. To create a class use the keyword class followed by class name beginning with an uppercase letter.
A company belongs to class called company class and can have the attributes say first-name and last-name and behaviour methods say showFullName().
Ex :
you can define a method inside a class the first argument to the method must be self where self – is a pointer to the class instance. self must be passed as an argument to the method, though the method does not take any arguments.