Nested for loops and print statements

Cai Gengyang gengyangcai at gmail.com
Mon Sep 26 01:59:38 EDT 2016


Why is it that you need a print() at the end to create the table for example 1:

Example 1 ---

>>> for row in range(10):
    for column in range(10):
        print("*",end=" ")
 
    # Print a blank line for next row
    print()

    
* * * * * * * * * * 
* * * * * * * * * * 
* * * * * * * * * * 
* * * * * * * * * * 
* * * * * * * * * * 
* * * * * * * * * * 
* * * * * * * * * * 
* * * * * * * * * * 
* * * * * * * * * * 
* * * * * * * * * * 

but not for Example 2 ---

for row in range(10):
    print("*",end=" ")

* * * * * * * * * *

When I try to do example 1 without the print() statement at the end, I get this error :

for row in range(10):
    for column in range(10):
	print("*",end=" ")
	
SyntaxError: inconsistent use of tabs and spaces in indentation



More information about the Python-list mailing list