Python example to define a class

Characterizing a class in Python: In this program/example, we will figure out how to characterize a class, how to characterize a trait, how to make an object of the class and how to get to the characteristic?

The undertaking to characterize a class in Python.

Here, we are characterizing a class named Number with a quality num, instating it with a worth 123, at that point making two items N1 and N2 lastly, printing the article’s memory areas and traits esteem utilizing the item names.

Python code to characterize a class:

# Python code to define a class

# class definition
class Number():
    num = 123

# main code
if __name__ == "__main__": 
    # creating first object 
    N1 = Number()
    #Printing object's memory (in hexadecimal)
    #Accessing and printing Class's Attribute

    # creating first object 
    N2 = Number()
    #Printing object's memory (in hexadecimal)
    #Accessing and printing Class's Attribute


<__main__.Number object at 0x7f96c06a0160>
<__main__.Number object at 0x7f96c06a06d8>

Leave a Comment

error: Alert: Content is protected!!