Python functions that can change their own input

I want to create a Python function that can check for its own input, and not the output of its input. For example, the raw_str function, which accurately returns its input as a string:

>>> raw_str(2+2) '2+2' 

but not:

 >>> str(2+2) '4' 

Is there any way to do this?

+4
source share
1 answer

This is not possible because the arguments are evaluated before they are passed to the function, so there is no way to distinguish between 2 + 2 and 3 + 1 (for example) inside the body of the function. Without additional context, it is difficult to propose possible solutions to the problem.

+10
source

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


All Articles