位置: 编程技术 - 正文
推荐整理分享Python内置函数—vars的具体使用方法(python内置函数用来打开或创建文件并返回文件对象),希望有所帮助,仅作参考,欢迎阅读内容。
文章相关热门搜索词:python内置函数什么用来返回序列中的最大元素,python内置函数用来打开或创建文件并返回文件对象,python内置函数可以返回列表 元组 字典 的元素个数,python内置函数什么可以返回列表元组,python内置函数什么用来返回序列中的最大元素,python内置函数用来返回列表,元组,字典,python内置函数什么可以返回列表元组,python内置函数什么可以返回列表元组,内容如对您有帮助,希望把文章链接给更多的朋友!
本文文章主要介绍了Python内置函数—vars的具体使用方法,分享给大家,具体如下:
英文文档:
vars([object])
Return the __dict__ attribute for a module, class, instance, or any other object with a __dict__ attribute.Objects such as modules and instances have an updateable __dict__ attribute; however, other objects may have write restrictions on their __dict__ attributes (for example, classes use a dictproxy to prevent direct dictionary updates).Without an argument, vars() acts like locals(). Note, the locals dictionary is only useful for reads since updates to the locals dictionary are ignored.
参数
object -- 对象
返回值
返回对象object的属性和属性值的字典对象,如果没有参数,就打印当前调用位置的属性和属性值 类似 locals()。
说明
1. 当函数不接收参数时,其功能和locals函数一样,返回当前作用域内的局部变量。
2. 当函数接收一个参数时,参数可以是模块、类、类实例,或者定义了__dict__属性的对象。
本函数是实现返回对象object的属性和属性值的字典对象。如果默认不输入参数,就打印当前调用位置的属性和属性值,相当于locals()的功能。如果有参数输入,就只打印这个参数相应的属性和属性值。
例子:
结果输出如下:
标签: python内置函数用来打开或创建文件并返回文件对象
本文链接地址:https://www.jiuchutong.com/biancheng/377051.html 转载请保留说明!上一篇:Python实现基本数据结构中栈的操作示例(python提供三种基本数值类型)
下一篇:Python numpy生成矩阵、串联矩阵代码分享(python生成矩阵的方法)
友情链接: 武汉网站建设