Is it possible in Python to overload the colon?

Of course, as a man, you must understand that if the answer is "Yes", you should explain how to do it.
March 23rd 20 at 19:19
2 answers
March 23rd 20 at 19:21
Solution
No, it will not work.
The list of special methods that are possible for the overload is strictly defined in the documentation.
Among them not mentioned the possibility of overloading the operator the colon (colon), as such operator does not exist at the moment in Python, but this character (colon) is part of the syntax for getting a slice from a list, tuple, string etc.
Example:
countries = ["USA", "France", "Canada", "China"]
last_country = countries[-1:]

And this symbol is a marker for the beginning of the announcement of the code block for the if, while, for, def and class
Example:
if expr:
 stmt

while expr:
stmt1
 stmt2

for x in sequence:
stmt1
 stmt2

def my_function():
stmt1
 stmt2

class MyClass:
 pass

The list of special methods that are possible for the overload is strictly defined in the documentation.

Hopefully, you won't. - Wilmer_Kohler79 commented on March 23rd 20 at 19:24
March 23rd 20 at 19:23
You can of course. Just rewrite the parser of the interpreter cpython. And change the grammar. :)

Find more questions by tags Python