Object / class in python

Total Post:113

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

Define and Objects and Class with example in python ?

  1. Post:140

    Points:984
    Re: Object / class in python

    Python Classes/Objects :

    Python is an object oriented programming language(Oop's concept). Almost everything in Python is an object,with methods. 

    Create a Class: 

    class MyClass: 
      x = 5

    Create Object: 

    p1 = MyClass() 
    print(p1.x)

    Object Methods: 

    Objects can also contain methods. Methods in objects are functions that belongs to the object. 

    class Person: 

     def __init__(self, name, age): 
        self.name = name
        self.age = age
    def myfunc(self):
        print("Hello my name is " + self.name)
    p1 = Person("Prakash", 19)
    p1.myfunc()

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!