0
why i am getting this error in python? Can anyone explain?
This below code executes perfectly. But when i place if-elif-else ladder below init i.e outside of init method I am getting error named "NameError: name 'Warrior' is not defined". Why i am getting that error can anyone help me to sort it out. This is the code. https://code.sololearn.com/cYz1lPrup1TY/#py
2 Antworten
+ 1
Because you already initialize the Warrior object with __init__(self).
So, 'Warrior' in if-else statement mean Warrior object, not Warrior class. Replace 'Warrior' with 'self' in if- statement, it'll be the same.
If you put off if-else statement outside of init method, it'll throw error because there is no name 'Warrior' in the scope of Class Warrior.
I hope it clear :)
0
Yes my doubt is clarified. Thank you Mr. Sylar