We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,466 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?

Function from method: increment and decrement without function definition

0
By Tony Veijalainen on Feb 20th, 2013 9:35 pm

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

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

vegaseat
DaniWeb's Hypocrite
Moderator
6,478 posts since Oct 2004
Reputation Points: 1,447
Solved Threads: 1,612
Skill Endorsements: 37

... 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.

paddy3118
Light Poster
40 posts since Sep 2007
Reputation Points: 21
Solved Threads: 11
Skill Endorsements: 0

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0616 seconds using 2.68MB