Print() is buggy, a string multiplied by n times is buggy

print(''a " *++++++++++++++++++++++++++ 5)

Technically it must not give output as a 5 times, but it runs smoothly.
Irrespective of “+” or “-” operator repeated n times, it doesn’t impact the function.

On what technical grounds should it not give an output of a a a a a ?

1 Like

The reason this looks wrong is because of deceptive whitespace. The plus is acting as a unary operator on 5, i.e. it is saying “positive five”. The grammar allows you to stack up unary operators if you want to, so it’s valid to say +++5[1]. You could mix + and - if you like, although a negative number won’t print anything.

print("a " * +-+-5)

So the code is just saying print("a " * 5) but the string of + and the whitespace makes it look like it shouldn’t work.


  1. “positive (positive (positive five)))” ↩︎

4 Likes