4

Today I saw a python program with a strange typo. Instead of

a_1 = 2

it contained the line

a:1 = 2

which does not raise a syntax error but instead assigns the value 2 to the variable a and ignores the ":1" completely.

Instead of ":1" you can add any combination of a colon and an evaluable expression.

Even

a:2+3*4=120

works! It assigns 120 to a and ignores 2+3*4.

Or try this:

a:print(4)=5

This line assigns 5 to a and executes the print function.

Who can explain this behaviour to me? In which situations does this syntax make sense?

Cœur
  • 34,719
  • 24
  • 185
  • 251
Marvo
  • 513
  • 6
  • 15

0 Answers0