Python--使用技巧(查看类结构)

来源:互联网 发布:中国网络电影演员 编辑:程序博客网 时间:2024/06/08 03:29

对于我这样的初学者,大概没有比在编程中能够快速查找帮助文档更重要的事情了。

在Python命令行的编程环境中,查找类结构可以通过以下命令

import mathdir(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']math.ceil.__doc__'ceil(x)\n\nReturn the ceiling of x as a float.\nThis is the smallest integral value >= x.' help(math.pow)Help on built-in function pow in module math: pow(...)    pow(x, y)         Return x**y (x to the power of y).

dir(math):显示math这个类的结构,包含的变量和方法

math.ceil.__doc__:ceil方法的介绍(英文两道下划线)

help(math.pow):pow方法的实现代码