python~type(获取变量类型)、help(某个函数或者类用法帮助文档) 、dir(类模块中可用函数)、查看文档
1.type(获取变量类型)
#encoding=utf-8b = "test"print(type(b)) #
脚本性语言,经常需要运行期间,来确定一个变量的类型,所以很常用。 2.help(某个函数或者类用法帮助文档)
#encoding=utf-8
import time
print (help(time))
"""
Help on module time:NAME
time - This module provides various functions to manipulate time values.FILE
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/time.soMODULE DOCS
http://docs.python.org/library/timeDESCRIPTION
There are two standard representations of time.One is the number
of seconds since the Epoch, in UTC (a.k.a. GMT).It may be an integer
or a floating point number (to represent fractions of seconds).
The Epoch is system-defined;
on Unix, it is generally January 1st, 1970.
The actual value can be retrieved by calling gmtime(0).The other representation is a tuple of 9 integers giving local time.
The tuple items are:
year (four digits, e.g. 1998)
month (1-12)
day (1-31)
hours (0-23)
...
"""print (help(time.sleep))"""
Help on built-in function sleep in module time:sleep(...)
sleep(seconds)Delay execution for a given number of seconds.The argument may be
a floating point number for subsecond precision.
"""
help(time)可以详细查看time类的详细文档,包括它里面都有那些函数,函数的用法介绍等。 help(time.sleep) 可以更加详细查看模块中函数的参数。 3.dir(类模块中可用函数)
import timeprint(dir(time))"""
['__doc__', '__file__', '__name__', '__package__', 'accept2dyear', 'altzone', 'asctime', 'clock', 'ctime', 'daylight', 'gmtime', 'localtime', 'mktime', 'sleep', 'strftime', 'strptime', 'struct_time', 'time', 'timezone', 'tzname', 'tzset']
"""
可见,dir可以方便查询一个python模块,如time模块中,都有那些函数可以使用 4.查看python api文档
python -m pydoc -g
【python~type(获取变量类型)、help(某个函数或者类用法帮助文档) 、dir(类模块中可用函数)、查看文档】
推荐阅读
- python学习之|python学习之 实现QQ自动发送消息
- 逻辑回归的理解与python示例
- python自定义封装带颜色的logging模块
- 【Leetcode/Python】001-Two|【Leetcode/Python】001-Two Sum
- Python基础|Python基础 - 练习1
- Python爬虫|Python爬虫 --- 1.4 正则表达式(re库)
- Python(pathlib模块)
- python青少年编程比赛_第十一届蓝桥杯大赛青少年创意编程组比赛细则
- Python数据分析(一)(Matplotlib使用)
- EditText默认不获取焦点弹出键盘