0

On the grounds that, according to the famous "Zen of Python" document, "explicit is better than implicit", to the point that we have to declare "self" as a parameter in each and every method, why does Python use type inference? Isn't it more in line with the "explicit is better than implicit" philosophy, a declaration of this kind

int i = 1

Rather than...

i = 1
A. N. Other
  • 409
  • 4
  • 14
  • 2
    Because Python puts the type information in the objects, not the variables. Quite explicitly! – Martijn Pieters Jan 29 '17 at 13:02
  • 1
    I'm closing this as a dupe of a post that explains strong typing vs dynamic typing. Python is dynamically typed, what you are asking is why it doesn't have *static* typing instead. – Martijn Pieters Jan 29 '17 at 13:09
  • I was asking about Python's general philosophy, as explained in the "Zen of Python" document, and how that is actually implemented in the language, in particular the "explicit vs implicit" matter. Yes, in other words why wouldn't static typing be more in line with the "Zen" document? But if you think the question is not relevant enough, then it's ok for me. – A. N. Other Jan 29 '17 at 13:16
  • Python *is* explicit here, the type information is just not stored in the variable names. Note that Python 3.5 introduces *optional type hints* that let static analysis tools verify that dynamic types match static expectations. – Martijn Pieters Jan 29 '17 at 13:23

0 Answers0