Why can't Python just be smart enough to cast x automatically (like every other language I work with)?<p>I imagine there is a not-bad reason, as Guido is pretty damn smart, but it's beyond me.
You haven't work with that many languages, have you :)<p>>>> x = 3 + "7"<p>What type should be x now: int or str ?<p>Also: "10" is lesser than "2" but 10 is greater 2.<p>Should (3 + "7") > 2 return true ?<p>Such automatic conversions forces you to remember many arbitrary rules, and when you forget it, you have bug that shows later.<p>It's easier to just write that str() (or use operator %).
If you want Python to "be smart enough to cast x automatically", then you want a weakly typed language. Weakly typed languages are difficult to reason about.<p>For example, should "3" == 3? Should 3 automatically be converted to "3" in that instance, or vice-versa?<p>Anyway, a better solution is:
print "x: %s" % x
See <a href="http://www.python.org/dev/peps/pep-0020/" rel="nofollow">http://www.python.org/dev/peps/pep-0020/</a>:<p><pre><code> Explicit is better than implicit.</code></pre>