python learning extension (enlargement method)

Blogger: Light of Destiny

Column: Python Programming

Table of contents

__name__ attribute function

dir() function: View the available properties and functions of the module.

help() function---View detailed description information of modules, functions, etc.

__name__ attribute (note that there are two underscores at both ends of __name__)

# View all built-in module names

Summarize


__name__ attribute function

  • Every Python script has a __name__ attribute (double underscores before and after) when run.
  • If the script is imported as a module, the value of its __name__ attribute is automatically set to the module name;
  • If the script is run standalone, its __name__ attribute value is automatically set to '__main__'.

dir() function: View the available properties and functions of the module.

>>> import math
>>> dir(math)
['__doc__', '__name__', '__package__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2',
'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'hypot', 'isinf', 'isnan', 'ldexp',
'lgamma', 'log', 'log10', 'log1p', 'modf', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan',
'tanh', 'trunc']
>>>

help() function---View detailed description information of modules, functions, etc.

>>> import math
>>>help(math.sin)
Help on built-in function sin in module math:
sin(x, /)
Return the sine of x (measured in radians).

__name__ attribute (note that there are two underscores at both ends of __name__)

This property holds the name of the current module during execution.

  • When a program module runs independently, the __name__ attribute is automatically assigned the string value "__main__".
  • If a program module is imported and used by other programs, its __name__ attribute is automatically assigned a string value of the module name (file name).

# View all built-in module names

import sys
sys.builtin_module_names

Summarize

1. Understand the development history and application fields of Python, and understand the characteristics of the Python language.

2. Understand the Python version.

3. Be proficient in installing and initially using Python. (emphasis)

4. Understand the running process of Python programs and Python file types. (emphasis)

5. Be proficient in using pip to manage Python extension libraries, as well as the import and preliminary use of modules. (main difficulty)

6. Master the composition and coding standards of Python programs. (emphasis)

Good study habits shape the future

Guess you like

Origin blog.csdn.net/VLOKL/article/details/133417986