Class in Python?

Total Post:113

 487  View(s)
Rate this:

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

  1. Post:140

    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(): 
    def inputName(self,fname,lname): self.fname=fname self.lastname=lastname
    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

    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.


Please check, If you want to make this post sponsored

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