Advertisement



< Prev
Next >



Python - Classes




In Python, by creating a class we could define a new type of objects. A class is defined with a set of attributes, such as methods and instance variables, which are shared by each object of the class.

A method is a place where the logic of a class is stored and a class may have zero or more methods defined in it. A class may also have some instance variables declared in it, which are used to represent the state of each object of the class. Before we create a class, let us understand the naming conventions set by Python for a class and its attributes.




Python naming conventions -







Note :








In the upcoming example, we are going to create a skeletal class i.e. a class without any of its own methods or instance variables defined in it. To create a skeletal class, we must use the pass keyword which allows us to pass the class definition.

# Python - A skeletal class without methods and instance variables


class Test:
    pass

ob = Test()
print(ob)


Output


<__main__.Test object at 0x0000000002EBEEB8>

As you can see in the program, we have first created a skeletal class(without any methods or instance variables) using the pass keyword, next we have created an object of this class and have got the representation of the object's address in the memory by printing this newly created object of the class.


Please share this article -





< Prev
Next >
< Python conditional operator
Python constructors >



Advertisement

Please Subscribe

Please subscribe to our social media channels for daily updates.


Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page




Advertisement

Notifications



Please check our latest addition

PYTHON


Advertisement