TypeError: User.__init__() missing 1 required positional argument:

TypeError: User.__init__() missing 1 required positional argument:

In python TypeError: User.__init__() missing 1 required positional argument: we face this error message when we create a class and use __init__() and miss 1 argument or 1 input value 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,username):
        self.username = username
        print("New user being created...")
     

user_1 = User()
print(user_1.username)


user_2 = User("Blog")
print(user_2.username)

Error Massage

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

Wrong code line

user_1 = User()

Correct code line

user_1 = User("Amol")
  • Wrong action: Outside or user_1 = User().
  • Correct action: Insite with user_1 = User(“Amol”).

Entire Correct Code line

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

user_1 = User("Amol")
print(user_1.username)


user_2 = User("Blog")
print(user_2.username)

Out-put

New user being created...
Amol
New user being created...
Blog

What is TypeError: User.init() missing 1 required positional argument:?

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

How to fix TypeError: User.init() missing 1 required positional argument:?

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

For more information Visit YouTube Channel.

Scroll to Top
Top 7 Gaming Project In python Save ₹25,000 Laptop under ₹11,999 Top 7 Funny error in Python Unicodeescape Most dangerous error in Python Hero Electric Battery Price In 2023