首页 > 编程语言 > 详细

4 Python基础_自查函数汇总

时间:2021-04-01 14:00:36      阅读:15      评论:0      收藏:0      [点我收藏+]

一 自查函数汇总

一 dir()和help()说明:

#说明:
1 python内置了很多内置函数、类方法属性及各种模块。
2 当我们想要当我们想要了解某种类型有哪些属性方法以及每种方法该怎么使用时,
3 我们可以使用dir()函数和help()函数在python ide交互式模式下获得我们想要的信息。

dir():用来查询一个类或者对象所有属性,比如:
help():函数帮助我们了解模块、类型、对象、方法、属性的详细信息
    详细信息包括:类的创建方式、属性、方法

二 help()查看功能

1 查看python所有的关键字:help("keywords")
2 查看python所有的modules:help("modules")
3 查看python所有的modules中包含指定字符串的modules: help("modules yourstr")
4 查看python中常见的topics: help("topics")
5 查看python标准库中的module:import os.path + help("os.path")
6 查看python内置的类型:help("list")
7 查看python类型的成员方法:help("str.find") 
8 看查python内置函数:help("open")
9 查看数据类型  print type (变量名)   
10 查看python中的关键字  import keyword
                      keyword.kwlist

三 dir()结果展示

>>> dir(list)
[‘__add__‘, ‘__class__‘, ‘__contains__‘, ‘__delattr__‘, ‘__delitem__‘, ‘__dir__‘, ‘__doc__‘, ‘__eq__‘, ‘__format__‘, ‘__ge__‘, ‘__getattribute__‘, ‘__getitem__‘, ‘__gt__‘, ‘__hash__‘, ‘__iadd__‘, ‘__imul__‘, ‘__init__‘, ‘__iter__‘, ‘__le__‘, ‘__len__‘, ‘__lt__‘, ‘__mul__‘, ‘__ne__‘, ‘__new__‘, ‘__reduce__‘, ‘__reduce_ex__‘, ‘__repr__‘, ‘__reversed__‘, ‘__rmul__‘, ‘__setattr__‘, ‘__setitem__‘, ‘__sizeof__‘, ‘__str__‘, ‘__subclasshook__‘, ‘append‘, ‘clear‘, ‘copy‘, ‘count‘, ‘extend‘, ‘index‘, ‘insert‘, ‘pop‘, ‘remove‘, ‘reverse‘, ‘sort‘]
>>>

四 help()结果展示

>>> help(list)
Help on class list in module builtins:

class list(object)
 |  list() -> new empty list
 |  list(iterable) -> new list initialized from iterable‘s items
 |
 |  Methods defined here:
 |
 |  __add__(self, value, /)
 |      Return self+value.
 |
 |  __contains__(self, key, /)
 |      Return key in self.
 |
 |  __delitem__(self, key, /)
 |      Delete self[key].
 |
 |  __eq__(self, value, /)
 |      Return self==value.
 |
 |  __ge__(self, value, /)
 |      Return self>=value.
 |
 |  __getattribute__(self, name, /)
 |      Return getattr(self, name).
 |
 |  __getitem__(...)
 |      x.__getitem__(y) <==> x[y]
 |
 |  __gt__(self, value, /)
 |      Return self>value.
 |
 |  __iadd__(self, value, /)
 |      Implement self+=value.
 |
 |  __imul__(self, value, /)
 |      Implement self*=value.
 |
 |  __init__(self, /, *args, **kwargs)
-- More  --

4 Python基础_自查函数汇总

原文:https://www.cnblogs.com/pythonsql/p/14605801.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!