创新互联Python教程:dir()函数在python模块的使用
1、说明

创新互联专注于企业成都全网营销、网站重做改版、沁县网站定制设计、自适应品牌网站建设、H5场景定制、商城网站制作、集团公司官网建设、外贸网站建设、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为沁县等各大城市提供网站开发制作服务。
内建函数dir()可以找到在模块中定义的所有名称,并作为字符串列表返回。
如果没有给定参数,dir()函数罗列当前定义的所有名称。
2、实例
import Titan print(dir(Titan)) # 输出结果: ['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'age', 'name', 'sayBad', 'sayGood', 'sayNice'] print(dir()) # 输出结果: ['Titan', '__annotations__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__'] # 这里定义一个新的变量 sum = 30 print(dir()) # 输出结果: ['Titan', '__annotations__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'sum'] # 把定义的变量删除后 del sum print(dir()) # 输出结果: ['Titan', '__annotations__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__']
以上就是dir()函数在python模块的使用,希望对大家有所帮助。更多Python学习指路:创新互联python教程
本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。
标题名称:创新互联Python教程:dir()函数在python模块的使用
分享地址:http://www.jxjierui.cn/article/ccdiphc.html


咨询
建站咨询
