本文共 1315 字,大约阅读时间需要 4 分钟。
1、dir([object]):列出某个类型所有可用的方法
参数object,可以是对象、变量、类型。如:
>>> str1 = 'a'>>> dir(str1)#查看一下list中存在哪些内置函数>>> dir(list)['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delslice__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
2、help():查看函数用法详解
在使用python编写代码时,会经常使用python自带的函数或模块,对一些不常用的函数或模块不是很清楚时,就可以使用该命令去查看详细的帮助信息。 help()函数中的参数是函数的名字。如:查看字符串分割函数split>>> help(split)Traceback (most recent call last): File "", line 1, in NameError: name 'split' is not defined>>> help(str.split)Help on method_descriptor:split(...) S.split([sep [,maxsplit]]) -> list of strings Return a list of the words in the string S, using sep as the delimiter string. If maxsplit is given, at most maxsplit splits are done. If sep is not specified or is None, any whitespace string is a separator and empty strings are removed from the result.
转载地址:http://ydmdi.baihongyu.com/