Writing notes reading smart Python programming
#!/usr/bin/env python
By specifying the python interpreter via / usr / bin / env, you can call the default python interpreter in that environment without depending on a specific path. * However, it depends on the environment, so it is good or bad.
# -*- coding: utf-8 -*-
Specify which character code to interpret the source code.
if __name__ == '__main__':
main()
Variables and methods with names that have two consecutive underscores before and after indicate that they behave specially in Python.
The name of the module is stored as a character string in __name__
. When a module is executed as a script, the value " __main__
"is entered, and when it is called from another module, its own module name is entered, so it is not executed.
In Python, the Python file (.py) itself is a module.
A package is a module that can have multiple modules under it, and is a directory containing the files __init__.py
. __init__.py
is a module that represents the package itself. To add a module, just put the Python file under the directory.
print('Hello')
It is a minute in Python2 system, but since it is a function in Python3, it can be interpreted as both a sentence and a function by enclosing it in parentheses.
Follow PEP8.
Recommended Posts