zoukankan      html  css  js  c++  java
  • [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:PythonVirtualEnvPythonVirtualEnv_391Scripts> & 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:PythonVirtualEnvPythonVirtualEnv_391Scripts> python -V
    Python 3.9.1
    (4Project) PS D:PythonVirtualEnvPythonVirtualEnv_391Scripts> 

    如果是在Python2.7.9版本中:

    PS D:PythonVirtualEnvPython_279> python.exe .	mp.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

  • 相关阅读:
    Android开发经验一判断当前屏幕是全屏还是非全屏
    Android得到控件在屏幕中的坐标
    MyBatis简单的增删改查以及简单的分页查询实现
    Coreseek:第二步建索引及測试
    极静之渊
    统计电影票房排名前10的电影并存入还有一个文件
    AAA
    FreeLink开源呼叫中心设计思想
    树后台数据存储(採用webmethod)
    [乐意黎原创] 百度统计这个坑爹货
  • 原文地址:https://www.cnblogs.com/LeeCookies/p/15494873.html
Copyright © 2011-2022 走看看