Colon in the task, a: 1 = 2

Today I saw a python program with a weird typo. Instead

a_1 = 2

contained a string

a:1 = 2

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

Instead of ": 1", you can add any combination of colon and parsed expression.

Even

a:2+3*4=120

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

Or try the following:

a:print(4)=5

This line assigns 5 a and performs the print function. A.

Who can explain this behavior to me? In what situations does this syntax make sense?

+4
source share

Source: https://habr.com/ru/post/1689585/


All Articles