Variable
Python The variable of , It's underline (_) And the names of English numbers . In the beginning 1 Text must be underlined (_) Or letters .
value1 = 123
_value1 = 123
test_value = 123
TEST_VALUE = 123
Constant
Python Constant types are not supported . Habitual capital letters and underscores (_) To name .
PI = 3.14
MAX_BUFFER_SIZE = 1024
Document reference (__doc__)
module The beginning of ,class The beginning of , The function starts with triple double quotation marks """...""" Notes 、 As a document comment __doc__ You can refer to the notes .
mymod.py
Python
"""A sample module"""
class MyClass:
"""A sample class"""
def myfunc(self, x, y):
"""A sample function"""
return x + y
mytest.py
Python
import mymod
print mymod.__doc__ #=> A sample module
print mymod.MyClass.__doc__ #=> A sample class
print mymod.MyClass.myfunc.__doc__ #=> A sample function
help() You can also access notes .
Linux
$ python
>>> import mymod
>>> help(mymod)
Help on module mymod:
NAME
mymod - A sample module
FILE
/root/mymod.py
CLASSES
MyClass
class MyClass
| A sample class
|
| Methods defined here:
|
| myfunc(self, x, y)
| A sample function