3 ms·
Python 3 gets that one, but python 2.7 doesn't: $ python3 -c 'print("baffle".upper())' BAFFLE $ python -c 'print "baffle".upper()' BAfflE $ pytho
by llimllib 13y ago
Python 3 gets that one, but python 2.7 doesn't:
$ python3 -c 'print("baffle".upper())'
BAFFLE
$ python -c 'print "baffle".upper()'
BAfflE
$ python -c 'print u"baffle".upper()'
BAϬE
- deathanatos 13y agoIt's interesting that you get BAFFLE for the first one. I get the same result in both 3 and 2. Note first that the reason you get "BAϬE" is a bit of garbarge-in garbage-out. Strangely, the interpreter isn't rejecting that with the typical "SyntaxError: Non-ASCII character <char> in file" error; instead, it appears to be assuming ISO-8859-1, and then performing .upper(). You can fix that: python2 -c '# coding: utf-8 print u"baffle".upper()' (Note, of course, that the #coding needs to match your terminals encoding, which is likely UTF-8, but it isn't guaranteed.) That, for me, prints "BAfflE" in both Python 2 and 3 (adjusting for 3 by adding parens around print, and removing the u prefix on the literal.) I'm on Python 3.2, so perhaps 3.3 does better. (I'm behind on updates, but last I did update, Gentoo stable was still on 3.2.)
- llimllib 13y agoInteresting. I am on python 3.3, but I don't know if it's the updated interpreter that fixes the bug.