Jun-22-2019, 07:43 PM
Hi,
first, the error message does not match your code. Yes, you'll get an NameError, but it will say that
On your problem: Code in the main body (=everything not inside a function or class) is executed top to bottom, line by line. So in your 2nd code block line 13 is executed frist and than line 15. But in line 15 you do the variable assignment, thus calling the variables in line 13 won't work, as nothing is assigned there.
For learning. I highly recommend to use the official Python tutorial at docs.python.org. It's the best resource for beginners. And it's free - free to use and free from mistakes. The latter unfortunately does not apply to many books.
Regards, noisefloor
first, the error message does not match your code. Yes, you'll get an NameError, but it will say that
str1
is not known. When asking for help, please make sure you post the error message matching your code. Everything else in confusing.On your problem: Code in the main body (=everything not inside a function or class) is executed top to bottom, line by line. So in your 2nd code block line 13 is executed frist and than line 15. But in line 15 you do the variable assignment, thus calling the variables in line 13 won't work, as nothing is assigned there.
For learning. I highly recommend to use the official Python tutorial at docs.python.org. It's the best resource for beginners. And it's free - free to use and free from mistakes. The latter unfortunately does not apply to many books.
Regards, noisefloor