What is Nostr?
Ramin Honary /
npub1ft5…chga
2023-12-23 16:46:28

Ramin Honary on Nostr: Beware: #Python (today I learned) If you accidentally put a comma at the end of a ...

Beware: #Python (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,
Running thing(3) returns (4,) instead of just 4. When you think about it how Python implements multiple returns values as tuples, and that assigning multiple comma-separated values does not require values be enclosed in parentheses, it makes sense that this would be the case with Python syntax. But even so, it still caught me off guard, I would have expected a syntax error.
Author Public Key
npub1ft5hkgyyu2ev80qh8pw2ggtecawfza7zlmm0pwvuvhapwll568aq0ychga