+ 1
Name "word" is not defined.
in for statement we have "word". but this variable is not defined. how do we not getting error? here is the code: words = ["hello", "world", "spam", "eggs"] for word in words: print(word + "!")
5 odpowiedzi
+ 4
@Sahil...well,there is no need to define your variable word or any other variables in Python prior to using it ,like in other languages..eg: int a in other languages
in Python just a is enough & you could store anything in a like int, float ,string
+ 8
But your code is running fine.
https://code.sololearn.com/cPnheurJmyzp/?ref=app
+ 2
When we write like this:- "for i in range (9):" , "i" variable is defined instantly.
+ 1
show us your code..it will be easy to explain
0
There are 2 things which explain your case and also depict how python is awesome
1. word in your case is a reference variable which gets the reference of the elements of the list one by one iteratively
2. Python follows dynamic type casting that's the reason you do not need to give datatypes while assigning the variable.