Python is a dynamic, interpreted (bytecode-compiled) language. There are no type declarations of variables, parameters, functions, or methods in source code.
A Python program is just a text file that you edit directly.
Python is case sensitive so “a” and “A” are different variables.
The end of a line marks the end of a statement.
Comments begin with a ‘#’ and extend to the end of the line.
Blocks of code are delimited strictly using indentation rather than curly braces.
Python source files use the “.py” extension and are called “modules.”
A Python module can be run directly, or it can be imported and used by some other module.
When a Python file is run directly, the special variable “name” is set to “main“. Therefore, it’s common to have the boilerplate if name ==… when the module is run directly, but not when the module is imported by some other module.
#!/usr/bin/env python
# import modules used here -- sys is a very standard one
import sys
# Gather our code in a main() function
def main():
print 'Hello there', sys.argv[1]
# Command line args are in sys.argv[1], sys.argv[2] ...
# sys.argv[0] is the script name itself and can be ignored
# Standard boilerplate to call the main() function to begin
# the program.
if __name__ == '__main__':
main()
The docstring can be a single line, or a multi-line description, those are “triple quotes”.
def 函数名(参数列表):