Python 的帮助--help、dir、type

介绍下,查看函数或模块用途的几个函数

1.help()

作用: 用于查看函数或模块用途的详细说明

语法: help(obj)

返回值: 返回对象的帮助信息

# help('sys') # 查看 sys 模块的帮助
# help('str')
a=[1,2,3]
#help (a)   # 查看列表 list 帮助信息
help (a.append)  # 显示list的append方法的帮助
Help on built-in function append:


append(...)
    L.append(object) -- append object to end
2.dir()

作用:dir() 函数不带参数时,返回当前范围内的变量、方法和定义的类型列表;带参数时,返回参数的属性、方法列表。如果参数包含方法__dir__(),该方法将被调用。如果参数不包含__dir__(),该方法将最大限度地收集参数信息。

语法:dir(obj)

返回值:返回模块的属性列表

print dir([])
['__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']
3. type()

作用:只有第一个参数则返回对象的类型,三个参数返回新的类型对象。

语法: class type(name ,bases,dict)

name-类名

bases--元组

dict--字典,类内定义的命名空间变量

返回值:返回参数对象类型

python 的所有数据类型都是类,可以通过 type() 查看该变量的数据类型:

print type(1)
print type('aaaa')
print type([2])
print type({'aa':10})
<type 'int'>
<type 'str'>
<type 'list'>
<type 'dict'>


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值