Python pop quiz
How is this interpreted?
1.200,30
#programming #python
@vwbusguy@mastodon.online I know the answer because I tried it in Idle otherwise I wouldn’t have had the first clue.
@vwbusguy@mastodon.online pro tip: if you expect Python to interpret something a specific way, wrap it in a constructor.
For instance: a = float(1230,30)
Then, you’ll either get what you expected or an error telling you the problem.Hypothesis: My German friends/followers will be more likely to know the answer than my fellow Americans.
It is a tuple. Python supports multiple assignments and this can be achieved by comma separation. For example:
x, y = 1.200,30
x would be 1.2
y would be 30@vwbusguy@mastodon.online what does this have to do with German (I say as a native German speaker)?
@decathorpe Because “1.200,30” is how a German would write the American equivalent of “1,200.30”, so a German might be more likely to have tried this before and therefore might have a better chance at the result.
@vwbusguy@mastodon.online but … the thousands separator in Python is the underscore?
also, the dot and comma switcheroo is not a German-or-not-German thing, but an anglocentric-or-not-anglocentric thing 😁:
https://en.m.wikipedia.org/wiki/Decimal_separator#Hindu%E2%80%93Arabic_numerals
@decathorpe You’re proving that a German understands the answer 😅. Most Americans don’t know about this differentiation.
It seems there is a new proposal to make _ the thousands separator:
@vwbusguy@mastodon.online this PEP seems to be about printing, but you can already use _ in numeric literals like this:
one_million = 1_000_000
@decathorpe Fair enough, but python supported comma as the delimited for input, too.
“The new-style number-to-string formatting language will be extended to allow _ as a thousands separator, where currently only , is supported.”
@vwbusguy@mastodon.online oh that’s very cursed
@vwbusguy@mastodon.online @decathorpe@mastodon.social almost all of Europe uses the comma that way, don’t they? I know France does. I do love Python for allowing underscores as thousands separators.
@mikebabcock@floss.social @decathorpe@mastodon.social IIRC, that behavior is because python is a wrapper on C.



