原文章:https://www.cnblogs.com/sesshoumaru/p/6042322.html

 1. object类是Python中所有类的基类,如果定义一个类时没有指定继承哪个类,则默认继承object类。

>>> class A:
pass >>> issubclass(A,object)
True
  2. object类定义了所有类的一些公共方法。 >>> dir(object)
['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']
  3. object类没有定义 __dict__,所以不能对object类实例对象尝试设置属性值。 复制代码
>>> a = object()
>>> a.name = 'kim' # 不能设置属性
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
a.name = 'kim'
AttributeError: 'object' object has no attribute 'name' #定义一个类A
>>> class A:
pass >>> a = A()
>>>
>>> a.name = 'kim' # 能设置属性

python的object(转)的更多相关文章

  1. Python – Get Object’s Class Name | Ridge Solutions, Ireland

    Python – Get Object’s Class Name | Ridge Solutions, Ireland Python – Get Object’s Class Name Author: ...

  2. appium 与 selenium python解决python 'WebElement' object does not support indexing 报错问题问题

    再用selenium编写测试脚本时,发现出现python 'WebElement' object does not support indexing 报错问题问题,再找一些解决方法时,发现Appium ...

  3. python's object model

    [python's object model] 1.object.__init__(self[, ...])        如果subclass没有实现__init__,那么python类在实例化的时 ...

  4. python 类(object)的内置函数

    python 类(object)的内置函数 # python 类(object)的内置函数 ### 首先 #### 以__双下划线开头的内置函数 __ #### __往往会在某些时候被自动调用,例如之 ...

  5. 关于Python的Object继承

    今天在Coding的使用,使用了python的单例模式,发现了一个很有趣的问题. class x(object): __se = None a = None def __new__(cls): if ...

  6. [Python] 'unicode' object is not callable

    在Python中,出现'unicode' object is not callable的错误一般是把字符串当做函数使用了.

  7. Python的object和type理解及主要对象层次结构

    一.Object与Type 1.摘自Python Documentation 3.5.2的解释 Objects are Python’s abstraction for data. All data ...

  8. 《流畅的Python》Object References, Mutability, and Recycling--第8章

    Object References, Mutability, and Recycling 本章章节: Variables Are Not Boxes identity , Equality ,  Al ...

  9. selenium+Python(Page Object 设计模式实例)

    以下实例演示了采用了page Object设计模式的方式登录qq空间: 1.创建基础类page:在初始方法__init__()定义驱动的(driver),基本url(base_url)和超时时间(ti ...

随机推荐

  1. JUC源码分析-线程池篇(一):ThreadPoolExecutor

    JUC源码分析-线程池篇(一):ThreadPoolExecutor Java 中的线程池是运用场景最多的并发框架,几乎所有需要异步或并发执行任务的程序都可以使用线程池.在开发过程中,合理地使用线程池 ...

  2. MySQL 到底是怎么解决幻读的?

    ; 原理:将历史数据存一份快照,所以其他事务增加与删除数据,对于当前事务来说是不可见的. 2. next-key 锁 (当前读) next-key 锁包含两部分: 记录锁(行锁) 间隙锁 记录锁是加在 ...

  3. ARM TK1 安装kinect驱动

    首先安装usb库 $ git clone https://github.com/libusb/libusb.git 编译libusb需要的工具 $ sudo apt-get install autoc ...

  4. Python全栈开发:RabbitMQ/Redis/Memcache/SQLAlchemy

    Memcached Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度 ...

  5. 28. string类中方法练习

    1. 自己写trim方法 public class Demo3 { public static void main(String[] args) { System.out.println(myTrim ...

  6. MySQL 刷题知识点整理

    1. left join on 与 right join on, inner join on 的区别: left join on 把左表中的行全部展示,而将寻找右表中符合的行展示: right joi ...

  7. 关于元素的offsetHeight、line-htight

    最近在做一个自适应高度的加载时的瀑布效果,使用加载完毕后为其一个A容器设置style的高度的方式完成(原高度为0且超出部分裁剪),使用offsetHeight获取其子元素高度(所有子元素高度均相等), ...

  8. C++ 数组作为参数的传递

    //#include <iostream> //#include <conio.h> //using namespace std; // // //void are7(int( ...

  9. Apache 环境变量配置

    在path 中加入  C:\__S_D_K__\AndroidApache\apache-ant-1.9.14\bin 我的路径在C盘

  10. Delphi 中多线程同步的一些处理方法

    Delphi 中多线程同步的一些处理方法   当创建了多个线程,并且多个线程都要访问同一资源,,就有可能出现混乱,于是用Synchronize来控制,使同一时间只有一个线程使用那部分资源,Synchr ...