TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: Why is Python so strict about automatically casting differently typed literals?

2 pointsby noaharcabout 16 years ago
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.

2 comments

mcavabout 16 years ago
I 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.<p>For instance, string formatting doesn't require casts -- just pretend everything's a string:<p><pre><code> &#62;&#62;&#62; print "%s %s %s = %s" % (4, '-', 1, 3) 4 - 1 = 3</code></pre>
评论 #568370 未加载
bayareaguyabout 16 years ago
Explicit is better than implicit.