[Python]Python的class(类)中的object是什么意思
2021/11/1 20:12:34
本文主要是介绍[Python]Python的class(类)中的object是什么意思,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
class First_Name(): print("Cookies") class Last_Name(object): print("Lee") x=First_Name() y=Last_Name() print(dir(x)) print(dir(y))
最后的输出结果为:
(4Project) PS D:\PythonVirtualEnv\PythonVirtualEnv_391\Scripts> & d:/PythonVirtualEnv/PythonVirtualEnv_391/4Project/Scripts/python.exe d:/PythonVirtualEnv/PythonVirtualEnv_391/tmp.py Cookies Lee ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__'] ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__'] (4Project) PS D:\PythonVirtualEnv\PythonVirtualEnv_391\Scripts> python -V Python 3.9.1 (4Project) PS D:\PythonVirtualEnv\PythonVirtualEnv_391\Scripts>
如果是在Python2.7.9版本中:
PS D:\PythonVirtualEnv\Python_279> python.exe .\tmp.py Cookies Lee ['__doc__', '__module__'] ['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__'] 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)]
不继承object对象,只拥有了__doc__ , __module__ 和自己定义的变量,就是说这个类的命名空间只有三个对象可以操作;
继承object对象,拥有了很多可操作对象,这些都是类中的高级特性;
python3 中已经默认加载了object
这篇关于[Python]Python的class(类)中的object是什么意思的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-30Python中''') 是什么?-icode9专业技术文章分享
- 2024-11-26Python基础编程
- 2024-11-25Python编程基础:变量与类型
- 2024-11-25Python编程基础与实践
- 2024-11-24Python编程基础详解
- 2024-11-21Python编程基础教程
- 2024-11-20Python编程基础与实践
- 2024-11-20Python编程基础与高级应用
- 2024-11-19Python 基础编程教程
- 2024-11-19Python基础入门教程