英文文档

class object

Return a new featureless object. object is a base for all classes. It has the methods that are common to all instances of Python classes. This function does not accept any arguments.
Note:object does not have a __dict__, so you can’t assign arbitrary attributes to an instance of the object class.

说明:

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

>>> class A:
pass >>> issubclass(A,object)
True

  

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__']

  

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' # 能设置属性

  

zhuanzai

Python内置函数Object的更多相关文章

  1. python内置函数

    python内置函数 官方文档:点击 在这里我只列举一些常见的内置函数用法 1.abs()[求数字的绝对值] >>> abs(-13) 13 2.all() 判断所有集合元素都为真的 ...

  2. python 内置函数和函数装饰器

    python内置函数 1.数学相关 abs(x) 取x绝对值 divmode(x,y) 取x除以y的商和余数,常用做分页,返回商和余数组成一个元组 pow(x,y[,z]) 取x的y次方 ,等同于x ...

  3. Python内置函数进制转换的用法

    使用Python内置函数:bin().oct().int().hex()可实现进制转换. 先看Python官方文档中对这几个内置函数的描述: bin(x)Convert an integer numb ...

  4. Python内置函数(12)——str

    英文文档: class str(object='') class str(object=b'', encoding='utf-8', errors='strict') Return a string  ...

  5. Python内置函数(61)——str

    英文文档: class str(object='') class str(object=b'', encoding='utf-8', errors='strict') Return a string ...

  6. 那些年,很多人没看懂的Python内置函数

    Python之所以特别的简单就是因为有很多的内置函数是在你的程序"运行之前"就已经帮你运行好了,所以,可以用这个的特性简化很多的步骤.这也是让Python语言变得特别的简单的原因之 ...

  7. Python 内置函数笔记

    其中有几个方法没怎么用过, 所以没整理到 Python内置函数 abs(a) 返回a的绝对值.该参数可以是整数或浮点数.如果参数是一个复数,则返回其大小 all(a) 如果元组.列表里面的所有元素都非 ...

  8. 【转】实习小记-python 内置函数__eq__函数引发的探索

    [转]实习小记-python 内置函数__eq__函数引发的探索 乱写__eq__会发生啥?请看代码.. >>> class A: ... def __eq__(self, othe ...

  9. 【转】python 内置函数总结(大部分)

    [转]python 内置函数总结(大部分) python 内置函数大讲堂 python全栈开发,内置函数 1. 内置函数 python的内置函数截止到python版本3.6.2,现在python一共为 ...

随机推荐

  1. 【原创】谈一个数学教育专业的IT职业生涯

    2003年,有许多值得记住,第一个是非典,第二个就是高考数学卷.直到今年2019年,时隔16年,有人说2019年高考数学卷难度堪比2003年,但还没难到2003年的程度. 我,2003年高考,进考场先 ...

  2. Java集合框架中底层文档的List与Set

    Java集合框架中的List与Set // 简书作者:达叔小生 Collection -> Set 无序不重复 -> 无序HashSet,需要排序TreeSet -> List 有序 ...

  3. intellij idea http proxy config

    # custom IntelliJ IDEA properties #http proxy -DproxySet=true -Dhttp.proxyHost=127.0.0.1 -Dhttp.prox ...

  4. Luogu P5652 基础博弈练习题 (博弈论、图论)

    题目链接 https://www.luogu.org/problem/P5652 题解 好题,想了四小时-- 首先考虑如何判断胜负: 首先假设只有一个柱子,那就是奇败偶胜.不难发现最后一个奇数后面的偶 ...

  5. linux shell 之流程控制 if if else while

    (1)流程控制不可以为空: (2)if [ $(ps -ef | grep -c "ssh") -gt 1 ]; then echo "true"; fi 条件 ...

  6. idea如果发生@override is not allowed when implement 错误,可以在Project Structure-Modules中更改Language level,设置为6以上的。

  7. SRS之SrsServer::cycle()

    1. SrsServer 相关类定义 1.1 SrsServer 类定义 /** * SRS RTMP server, initialize and listen, * start connectio ...

  8. State Threads之网络架构库

    原文: State Threads for Internet Applications 介绍 State Threads is an application library which provide ...

  9. Git 推送文件到远程仓库

    Configure Git for the first time: git config --global user.name "xxxxx xx"git config --glo ...

  10. 一、基础篇--1.3进程和线程-CountDownLatch、CyclicBarrier 和 Semaphore

    下面对上面说的三个辅助类进行一个总结: 1)CountDownLatch和CyclicBarrier都能够实现线程之间的等待,只不过它们侧重点不同: CountDownLatch一般用于某个线程A等待 ...