设为首页 加入收藏

TOP

学会使用Python的帮助
2019-05-16 02:36:48 】 浏览:28
Tags:学会 使用 Python 帮助

常用的几种方式:

写在前面,个人最喜欢的一个功能是pycharm中的documentation内置显示(默认快捷键为Ctrl+Q),选中函数,Ctrl+Q如下:

也有External documetation,快捷键为Shift+F1

1. dir()主要用来查看对象的属性。
>>> a = [1,2,3]
>>> b = (1,2,3)
>>> print dir(a)
[..... 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
>>> print dir(b)
[.... 'count', 'index']
2. __doc__看属性文档
>>> a = [1,2,3]
>>> a.reverse.__doc__
'L.reverse() -- reverse *IN PLACE*'
3. help()信息比较详细
>>> a = [1,2,3]
>>> help(a)
Help on list object:
class list(object)
 "|  list() -> new empty list
 |  list(iterable) -> new list initialized from iterable's items
 |  
 |  Methods defined here:.....

 |  append(...)
 |      L.append(object) -- append object to end
 |  
 |  count(...)
 |      L.count(value) -> integer -- return number of occurrences of value
 |  
 |  extend(...)
 |      L.extend(iterable) -- extend list by appending elements from the iterable
 |  
 |  index(...)
 |      L.index(value, [start, [stop]]) -> integer -- return first index of value.
 |      Raises ValueError if the value is not present.
 |  
 |  insert(...)
 |      L.insert(index, object) -- insert object before index
 |  
 |  pop(...)
 |      L.pop([index]) -> item -- remove and return item at index (default last).
 |      Raises IndexError if list is empty or index is out of range.
 |  
 |  remove(...)
 |      L.remove(value) -- remove first occurrence of value.
 |      Raises ValueError if the value is not present.
 |  
 |  reverse(...)
 |      L.reverse() -- reverse *IN PLACE*
 |  
 |  sort(...)
 |      L.sort(cmp=None, key=None, reverse=False) -- stable sort *IN PLACE*;
 |      cmp(x, y) -> -1, 0, 1
 |  
 |  ----------------------------------------------------------------------
 |  Data and other attributes defined here:
 |  
 |  __hash__ = None
 |  
 |  __new__ = <built-in method __new__ of type object>
 |      T.__new__(S, ...) -> a new object with type S, a subtype of T
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇《Python入门》第一个Python Web.. 下一篇cmd中执行Python命令时>>&g..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目