5 ms·
Ask HN: Why is Python so strict about automatically casting differently typed literals?
I hate having to use str() and int() all the time. Am I doing something wrong? If not, what is the reasoning behind their requirement? I think most of the automatic casts are pretty well defined in any given situation.
- mcav 17y agoI rarely use str() and int() unless I'm doing conversion of user input (e.g. web apps). You'd have to be more specific about your usage. For instance, string formatting doesn't require casts -- just pretend everything's a string: >>> print "%s %s %s = %s" % (4, '-', 1, 3) 4 - 1 = 3
- makecheck 17y agoTrue, unless the format is inherently numerical; e.g. if you care about significant digits (something like "%.4f") or padding (something like "%4d"), there's no way to do it without an actual number.
- bayareaguy 17y agoExplicit is better than implicit.