Nested for loops and print statements
jmp
jeanmichel at sequans.com
Mon Sep 26 12:25:16 EDT 2016
On 09/26/2016 05:25 PM, Cai Gengyang wrote:
> I just wanted to note that sometimes the code works, sometimes it doesn't. (even though both are exactly the same code) ... Weird , dum dum dum
>
>>>> for row in range(10):
> for column in range(10):
> print("*",end="")
>
> SyntaxError: inconsistent use of tabs and spaces in indentation
>>>> for row in range(10):
> for column in range(10):
> print("*",end="")
Here,
from itertools import product
for row,column in product(range(10), range(10)): print("*", end="")
Problem solved :)
On a more serious note, they're not the same code, in the same way than
print("foo")
print("bar")
is not the same code than
print("foo")print("bar")
You're fooled by your editor which displays 2 different characters the
same way. Tab or space does matter in python, get over it and move on
with your python life. Actually python is a great debugger for
misconfigured text editors.
jm
More information about the Python-list
mailing list