import sys num_steps = int(sys.argv[1]) for x in range(1, num_steps+1): print (" " * (num_steps - x), "#" * x ) |
1 answer
print(x, y) inserts a default space between x and y . Therefore, the space remains even when x empty. Replace the comma with a + to print as one line: print(x + y) .
for people attracted here by the title of the question - not relevant to the task in the question itself:
You can use s = s.lstrip() to remove all spaces at the beginning of a line:
>>> ' \na \n'.lstrip() 'a \n' |

print('', 'a')andprint('', 'a', sep='')- MaxU