TypeError: .__init__() missing 2 required positional arguments:

TypeError: .init() missing 2 required positional arguments:

In python TypeError: .__init__() missing 2 required positional arguments: we face this error message when we create a class and use __init__() and miss 2 argument or 2 input values then the python interpreter shows this error message, If you want to fix this error you need to just use add argument or input value to your next line code, For more clarification see the below example.

Wrong Code

class User:
    
    def __init__(self, password, username):
        self.password = password
        self.username = username
        print("New user being created...")
     

user_1 = User()
print(user_1.username, user_1.password)


user_2 = User("BBBB","Blog")
print(user_2.username, user_2.password)

Error Massage

Traceback (most recent call last):
  File "/home/kali/python/webproject/quiz/17day/main.py", line 9, in <module>
    user_1 = User()
TypeError: User.__init__() missing 2 required positional arguments: 'password' and 'username'

Wrong code line

user_1 = User()

Correct code line

user_1 = User("PYTHON", "Python")
  • Wrong action: Outside or user_1 = User().
  • Correct action: In-site with user_1 = User(“PYTHON”, “Python”).

Entire Correct Code line

class User:
    
    def __init__(self, password, username):
        self.password = password
        self.username = username
        print("New user being created...")
     

user_1 = User("PYTHON", "Python")
print(user_1.username, user_1.password)


user_2 = User("BBBB","Blog")
print(user_2.username, user_2.password)

OUT-PUT

$ python3 main.py      
                                                                                                                                           
New user being created...
Python PYTHON

New user being created...
Blog BBBB

What is TypeError: .init() missing 2 required positional arguments:?

In python, we face this error message when we create a class and use __init__() and miss 2 argument or 2 input values then the python interpreter shows this error message.

How to fix TypeError: .__init__() missing 2 required positional arguments:?

If you want to fix this error you need to just use add 2 argument or 2 input value to your next line code, For more clarification see the above example.

For more information Visit YouTube Channel.

Scroll to Top
Mother’s Day Python Code Love calculator Miss Universe And You Check Your Love Score With K-POP Idols Check Your Love Score With Childhood Crush