making constructor in python 1

making constructor in python

class User:
    def __init__(self, user_id, user_name):
        self.user_id = user_id
        self.user_name = user_name
User1 = User(4383,"Empire of programmers")

Here is what the above code is Doing:
1. We created a class named User.
2. We defined the __init__() method. This method is called when an object is created from a class and it allows the class to initialize the attributes of the class.
3. We created an object named User1.
4. We printed the value of the user_id attribute.
5. We printed the value of the user_name attribute.

Similar Posts