我看了两个问题下的所有回答,发现都没有提到 Guido van Rossum (Benevolent Dictator For Life (BDFL))的意见,这里贴一下,提供更多信息。
“Weak typing is not really a fair description of what's going on in Python. It's really runtime typing because every object is labeled with a type.” by Guido van Rossum
他的意思就是,Python 是 runtime typing,不是 weak typing,那是不是就意味着 Python is a strongly typed language,好像也不是。Strong versus Weak Typing
A Conversation with Guido van Rossum, Part V
by Bill Venners with Frank Sommers
February 10, 2003
……
Guido van Rossum: One of the things I like about Python is that everything happens at runtime. Python's compile-time complexity is almost nonexistent compared to that complexity of languages like C++ or even Java, which is much simpler than C++ at compile time. Although, doesn't Sun plan to add generics to Java?
Bill Venners: Yes.
Guido van Rossum: Well, they have to, because it is a strongly typed language, and you can't do certain things with strong typing otherwise.
Weak typing is not really a fair description of what's going on in Python. It's really runtime typing because every object is labeled with a type. Bill Venners: Every object in Python does have a type.
Guido van Rossum: Every object does have a type. It is a string, an integer, a floating point number, a dictionary, or whatever.
Bill Venners: But method parameters and return values don't have types.
Guido van Rossum: Those variables don't have types. Runtime typing works differently, because you can easily make a mistake where you pass the wrong argument to a method, and you will only find out when that method is actually called. On the other hand, when you find out, you find out in a very good way. The interpreted language tells you exactly this is the type here, that's the type there, and this is where it happened. If you make a mistake against the type system in C or C++, and it only happens at runtime, you're in much worse shape. So you can't simply say strongly typed languages are better than runtime typed languages or vice versa, because you have a whole tradeoff of different parts.