In python NameError: name ‘Self’ is not defined. Did you mean: ‘self’? we face this error message when we create a class and use __init__(self [small s] ) and use as a Self [Capital S ] 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("PYTHON", "Python")
print(user_1.username, user_1.password)
user_2 = User("BBBB","Blog")
print(user_2.username, user_2.password)
Error Massage
File "/home/kali/python/webproject/quiz/17day/main.py", line 9, in <module>
user_1 = User("PYTHON", "Python")
File "/home/kali/python/webproject/quiz/17day/main.py", line 4, in __init__
Self.password = password
NameError: name 'Self' is not defined. Did you mean: 'self'?
Wrong code line
Self.password = password
Correct code line
self.password = password
- Wrong action: Self (Capital S).
- Correct action: self (small s).
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)
What is NameError: name ‘Self’ is not defined. Did you mean: ‘self’?
In python we face this error message when we create a class and use __init__(self [small s] ) and use as a Self [Capital S ] then the python interpreter shows this error message.
How to fix NameError: name ‘Self’ is not defined. Did you mean: ‘self’?
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 above example.
For more information Visit YouTube Channel.
