3 ms·
> things that did change didn't actually make a clear difference in [...] the clarity of your code print "%s remember to %s in %s if %s but never %s" % (some_r
by toyg 11y ago
> things that did change didn't actually make a clear difference in [...] the clarity of your code
print "%s remember to %s in %s if %s but never %s" % (some_random_tuple)
vs
print("{when} remember {what} in {room} if {condition} but never {dont}".format(* * dict_with_explicit_keys))
A bit verbose but much clearer and future-proof.
- icebraining 11y agoBut you can already do that in Python 2.7.
- mmarx 11y agoThat's an unfair comparison, however, print "%(when)s remember to %(what)s in %(room)s but never %(dont)s" % dict_with_explicit_keys was supported back in at least 2.4.
- Ded7xSEoPKYNsDd 11y agoPython 2.7 supports string.format and Python 3 supports % formatting. The only actual difference in that example is that print became a function in Python 3, requiring some additional parentheses. (Something that can be mechanically translated without much hassle.)
- GFK_of_xmaspast 11y agoWasn't the % formatting missing from early versions of python3?