Python学习之对象

来源:互联网 发布:政治工作 网络关 编辑:程序博客网 时间:2024/06/05 07:52

Python学习之对象

Python对象

对象的三个特征:
1. 身份:id()
2. 类型:type()
3. 值

内建类型

  • 整型 Integer
  • 布尔值 Boolean
  • 长整型 Long integer
  • 浮点型 Floating point real number
  • 复数型 Complex number
  • 字符串 String
  • 列表 List
  • 元组 Tuple
  • 字典 Dictionary

标准类型操作符

  • 对象值的比较
<>>=<===!=<>
操作符 功能 结果 < 小于 bool > 大于 bool <= 小于等于 bool >= 大于等于 bool == 等于 bool != 不等于 bool <> 不等于 bool
  • 对象身份的比较
isis not
操作符 功能 结果 is 是 bool is not 不是 bool

- 布尔类型

notandor
操作符 功能 结果 not 逻辑反 bool and 逻辑与 bool or 逻辑或 bool

标准类型内建函数

函数 功能 结果 cmp(obj1, obj2) 比较 int repr(obj) 或 `obj` 返回对象字符串 str str(obj) 返回可读性好的对象字符串 str type(obj) 返回对象类型 type isinstance(type) 判断是否是某类型的实例 bool

类型工厂函数

  • int(), long(), float(), complex()
  • str(), unicode(), basestring()
  • list(), tuple()
  • type()

  • dict()
  • bool()
  • set(), frozenset()
  • object()
  • classmethod()
  • staticmethod()
  • super()
  • property()
  • file()

标准类型总览

数据类型 存储模型 更新模型 访问模型 数字 标量 不可更改 直接访问 字符串 标量 不可更改 顺序访问 列表 容器 可更改 顺序访问 元组 容器 不可更改 顺序访问 字典 容器 可更改 映射访问

不支持的类型

  • char, byte
  • 指针
  • short, long
    Python中的int型实际就是C语音的long型。
  • double
    python中float其实就是C语音的double型。想更高精度可用decimal。
0 0
原创粉丝点击