Class in Python?

Total Post:113

Points:791
Python 
 487  View(s)
Ratings:
Rate this:

What is a Class? How do you create it in Python?

  1. Post:140

    Points:984
    Re: Class in Python?

    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.

Answer

Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.