當你給dir()提供一個模塊名字時,它返回在那個模塊中定義的名字的列表。當沒有為其提供參數時, 它返回當前模塊中定義的名字的列表。
dir() 函數使用舉例:
1
2
3
4
5
6
|
>>>
import
sys
# 獲得屬性列表,在這里是sys模塊的屬性列表
>>>
dir
(sys)
[
'__displayhook__'
,
'__doc__'
,
'__excepthook__'
,
'__name__'
,
'__package__'
,
'__stderr__'
,
'__stdin__'
,
'__stdout__'
,
'_clear_type_cache'
,
'_compact_freelists'
,
'_current_frames'
,
'_getframe'
,
'api_version'
,
'argv'
, ...]
|
如果您需要快速獲取任何的Python函數或語句的信息,那么您可以使用內置的“help”(幫助)功能。這是非常有用的,尤其是當使用翻譯提示符時,例如,運行‘help(print)”——這將顯示print函數的幫助--用於打印東西到屏幕上。
help()函數使用舉例:
1
2
3
4
5
6
|
>>> help(print)
Help on built-
in
function
print
in
module builtins:
print(...)
print(value, ..., sep=
' '
, end=
'\n'
,
file
=sys.stdout, flush=False)
...
|