Python对象
来源:互联网 发布:gnuradio linux 编辑:程序博客网 时间:2024/06/06 12:38
1. 自定义类型布尔值
自定义的类如果定义了__nonzero__()
或者__len__()
且值为0,那么它们的布尔值就是Flase
。
2. 对象比较
a is b# equivalent toid(a) == id(b)
3. 标准类型内建函数
- type()
- cmp()
- str()
- repr()
- isinstance()
3.1 type()
得到一个对象的类型,并返回相应的type对象。
>>> type(1)<type 'int'>>>> type('Furzoom')<type 'str'>>>> type(type(1))<type 'type'>>>>
3.2 cmp()
对于自定义类型,cmp()会调用__cmp__()
函数。
>>> a,b=1,2>>> cmp(a,b)-1>>> cmp(b,a)1>>> b=1>>> cmp(a,b)0>>> a,b='abc','xyz'>>> cmp(a,b)-1>>> cmp(b,a)1>>> b='abc'>>> cmp(a,b)0>>>
3.3 str() and repr()
通常情况下obj = eval(repr(obj))
。
repr()
与反引号运算符得到的结果是一样的。
3.4 isinstance()
返回对应是否是某种类型。
>>> isinstance(3, int)True
4. 类型工厂函数
- int(), long(), float(), double()
- str(), unicode(), basestring()
- list(), tuple()
- type()
- dict()
- bool()
- set(), frozenset()
- object()
- classmethod()
- staticmethod()
- super()
- property()
- file()
0 0
- Python对象
- python对象
- Python对象
- python 对象
- Python对象
- Python对象
- Python对象
- Python---对象
- Python 对象
- Python 对象
- python 对象
- python 对象
- Python -- 对象和面向对象
- Python对象之基础对象
- python中的对象 一级对象?
- Python学习笔记-Python对象
- Python核心编程----Python对象
- Python基础语法-Python对象
- APP开发实战51-APP架构设计
- 【GDOI2014模拟】服务器
- APP开发实战52-层次划分
- java写的记事本程序
- RamDisk ramfs tmpfs 详解
- Python对象
- Node.js(插件包)、Sublime text3安装与配置
- IOS UITableView单元点击事件
- 数据结构
- CentOs6.5 安装mysql
- 关于MySQL的一些命令
- 剑指offer(六十四)之滑动窗口的最大值
- json 的几种格式及处理
- [bzoj3211]花神游历各国