Nested for loops and print statements
Cai Gengyang
gengyangcai at gmail.com
Mon Sep 26 16:57:39 EDT 2016
Ok it works now:
>>>for row in range(10):
for column in range(10):
print("*",end="")
****************************************************************************************************
but how is it different from ---
>>> for row in range(10):
for column in range(10):
print("*",end="")
SyntaxError: inconsistent use of tabs and spaces in indentation
Why does the example on top work and the example below doesn't work ? The only difference is that the "print" statement is one space different from each other. Forgive me if i can't explain things clearly over the forum
On Tuesday, September 27, 2016 at 3:57:18 AM UTC+8, Larry Hudson wrote:
> On 09/26/2016 08:25 AM, 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
> >
>
> It is NOT weird. Python is being consistent, YOU are not.
>
> These examples are NOT "exactly the same code"! The indenting is different. Python (correctly)
> treats them as being different.
>
> YOU MUST USE CONSISTENT INDENTING. You MUST always use spaces (the recommended) or always use
> tabs. Never, ever, not at any time, can you mix them.
>
> (Now, does that emphasize the point enough?) Go back and REWRITE your code with CONSISTENT
> indenting.
>
> --
> -=- Larry -=-
More information about the Python-list
mailing list