无聊之人--除了技术,还是技术,你懂得
分类: Python/Ruby
2011-06-09 15:53:51
Note that the keyword def starts the function declaration, followed by the function name, followed by the arguments in parentheses. Multiple arguments (not shown here) are separated with commas.
Also note that the function doesn't define a return datatype. Python functions do not specify the datatype of their return value; they don't even specify whether or not they return a value. In fact, every Python function returns a value; if the function ever executes a return statement, it will return that value, otherwise it will return None, the Pythonnull value.
In Visual Basic, functions (that return a value) start with function, and subroutines (that do not return a value) start with sub. There are no subroutines in Python. Everything is a function, all functions return a value (even if it's None), and all functions start with def. 在VB中,带返回值的函数以function开始,不带返回值的subroutine以sub开始。在Python中没有subroutine。所有的对象(???)都是函数,所有的函数都有返回值(即使返回值为NONE,所有的函数以def开始 |
In Java, C++, and other statically-typed languages, you must specify the datatype of the function return value and each function argument. In Python, you never explicitly specify the datatype of anything. Based on what value you assign, Python keeps track of the datatype internally. 在Java和C++以及其它静态类型的语言中,你必需说明函数返回值的类型以及函数参数的类型。在Python中,你不必显示说明任何对象的类型。根据你的赋值,Python在内部始终记录该变量的类型。 |
An erudite reader sent me this explanation of how Python compares to other programming languages:
曾经有位资深读者发给我下面的内容,以便解释python与其它编程语言的比较