python学习扩展(放大招)

博主:命运之光

专栏:Python程序设计

目录

__name__属性作用

dir()函数: 查看模块的可用属性和函数。

help()函数---查看模块、函数等的详细说明信息。

__name__属性(注意__name__两端各有两个下划线)

# 查看所有内置模块名称

总结


__name__属性作用

  • 每个Python脚本在运行时都有一个__name__属性(前后双下划线)。
  • 如果脚本作为模块被导入,则其__name__属性的值被自动设置为模块名;
  • 如果脚本独立运行,则其__name__属性值被自动设置为'__main__'。

dir()函数: 查看模块的可用属性和函数。

>>> 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()函数---查看模块、函数等的详细说明信息。

>>> 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__属性(注意__name__两端各有两个下划线)

该属性保存当前模块执行过程中的名称。

  • 当一个程序模块独立运行时,该__name__属性自动被赋予值为”__main__”的字符串。
  • 如果一个程序模块被其他程序通过import导入使用,则其__name__属性自动被赋予值为模块名(文件名) 的字符串。

# 查看所有内置模块名称

import sys
sys.builtin_module_names

总结

1. 了解Python的发展史和应用领域,理解Python语言特点。

2. 了解Python版本。

3. 熟练掌握安装和初步使用Python。(重点)

4. 理解Python程序的运行过程、 Python文件类型。(重点)

5. 熟练掌握使用pip管理Python扩展库,以及模块的导入与初步使用方法。(重点,难点)

6. 掌握Python程序的组成和编码规范。(重点)

好的学习习惯成就未来

猜你喜欢

转载自blog.csdn.net/VLOKL/article/details/133417986