1.11M Members

Function from method: increment and decrement without function definition

 
0
 

You can fix one parameter of function call by calling underlying method of fixed parameter instead of using functools.partial or lambda statement.

inc = (1).__add__
print(inc(4))
#5
sub = (-1).__radd__
print(sub(5))
#4
Member Avatar
Tony Veijalainen

Specialties:
IT/Science/Contracts/Religious translation/interpreting FIN-ENG-FIN
Python programming

 
0
 

Actually, nothing beats the convenience of C language n++ and n--
The eggheads of Python have discussed this, but have not acted.

 
0
 

... The argument about n++ and n-- is that there is also --n and ++n and that C allows assigning as well as auto increment/decrement in one statement, which is both error prone and hard to maintain.

Overall, I'm happy with the decision to leave it out of Python. writing x += 1 and not having to read and debug some horrible x, y = ++y, x++ or whatever is fine.

Isn't it about time forums rewarded their contributors?

Earn rewards points for helping others. Gain kudos. Cash out. Get better answers yourself.

It's as simple as contributing editorial or replying to discussions labeled or OP Kudos

You
This is an OP Kudos discussion and contributors may be rewarded
Post:
Start New Discussion
View similar articles that have also been tagged: