ramin_hal9001,
@ramin_hal9001@emacs.ch avatar

Beware: (today I learned)

If you accidentally put a comma at the end of a return statement, a 1-tuple is returned:

def thing(x): return x+1,thing(3) # returns (4,) instead of 4

When you think about it, it makes sense: Python implements multiple returns values as tuples, and tuples ending with a comma are 1-tuples, and that for either assigning or returning multiple comma-separated values you are not required to enclose values in parentheses, it makes sense that this would be the case with Python syntax. But even so, it still caught me off guard and crashed my program, I would have expected a syntax error.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • python
  • DreamBathrooms
  • ngwrru68w68
  • InstantRegret
  • magazineikmin
  • thenastyranch
  • rosin
  • khanakhh
  • tacticalgear
  • Youngstown
  • slotface
  • Durango
  • kavyap
  • mdbf
  • ethstaker
  • JUstTest
  • GTA5RPClips
  • modclub
  • tester
  • Leos
  • osvaldo12
  • cisconetworking
  • everett
  • cubers
  • normalnudes
  • anitta
  • megavids
  • provamag3
  • lostlight
  • All magazines