python命令行进入帮助模式_python命令行模式直接查看帮助
python命令行模式直接查看幫助
使用python的時候經常要上網查詢某個函數,類或者模塊的用法,這樣來回切換很麻煩的,并且很耗時間。如果你沒有聯網的情況下,更是沒有辦法。那能不能直接在python命令行模式直接查看幫助?
答案是可以,并且真的很簡單:
$ python
Python 2.7 (r27:82525, Jul? 4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>>
進入python的命令行模式后,有2種選擇來使用幫助
交換式的help模式
直接使用help()函數
交換式的help模式
>>> help()
就直接進入help的交換模式
然后查看任何你想看的
函數
例如查看函數 abs
help> abs
類
例如查看 list
help> list
模塊
例如查看 sys
help> sys
要退出幫助內容,按q即可
要help交互式模式,也是q,然后回車
直接使用help()函數
這種方法是有個需要注意如果沒有導入模塊,則不能查看模塊,例如
>>> help( sys )
會報錯。
需要先導入
>>> import sys
>>> help( sys )
這樣就可以
但是查看函數和類沒有問題
例如,查看abs函數
>>> help( abs )
例如, 查看list這個類
>>> help( list )
Help on class list in module __builtin__:
class list(object)
|? list() -> new empty list
|? list(iterable) -> new list initialized from iterable's items
|
|? Methods defined here:
|
|? __add__(…)
|????? x.__add__(y) <==> x+y
|
|? __contains__(…)
|????? x.__contains__(y) <==> y in x
|
|? __delitem__(…)
|????? x.__delitem__(y) <==> del x[y]
|
|? __delslice__(…)
|????? x.__delslice__(i, j) <==> del x[i:j]
|
|????? Use of negative indices is not supported.
|
|? __eq__(…)
|????? x.__eq__(y) <==> x==y
|
|? __ge__(…)
|????? x.__ge__(y) <==> x>=y
|
|? __getattribute__(…)
|????? x.__getattribute__('name') <==> x.name
|
— More? —
版權所有,禁止轉載. 如需轉載,請先征得博主的同意,并且表明文章出處,否則按侵權處理.
分享到:
總結
以上是生活随笔為你收集整理的python命令行进入帮助模式_python命令行模式直接查看帮助的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python朋友圈评论_利用Python
- 下一篇: websocket python爬虫_p