Python数据模型——内置类型

1.None

  • 此类型只有一种取值,是一个具有此值的单独对象,该对象通过内置名称None访问。
  • 在许多情况下用来表示空值。
  • 未显示指定返回值的函数将返回None。
  • None的逻辑值为假。
print(type(None)) # <class 'NoneType'>

2.NotImplemented

  • 此类型只有一种取值,是一个具有此值的单独对象,该对象通过内置名称NotImplemented访问。
  • 进行数值比较时如果未实现指定的运算符重载方式,则应该返回此值
  • NotImplemented的逻辑值为真。
print(type(NotImplemented))  # <class 'NotImplementedType'>

3.Ellipsis

  • 此类型只有一种取值,是一个具有此值的单独对象, 该对象通过字面值 … 或内置名称 Ellipsis 来访问。
  • 他的逻辑值为真。
print(type(Ellipsis))  # <class 'ellipsis'>

4.number.Number

  • 此类型的对象由数字字面值来创建。
  • 数字对象是不可变的。

    4.1. numbers.Integral

    • 整形(int):此对象表示任意大小的数字,受限于可用的内存
    print(type(0))  # <class 'int'>
    
    • 布尔型(bool):此对象表示逻辑值False和True
    print(type(False))  # <class 'bool'>
    

    4.2. numbers.Real

    • 浮点数类型(float)
    print(type(0.0))  # <class 'float'>
    

    4.3. numbers.Complex

    • 复数类型(complex)
    com = 1 + 2j
    print(type(com))  # <class 'complex'>
    print(com.real, com.imag)  # 1.0 2.0
    

5. 序列

  • 此类型对象表示一个有限的集合,通过内置函数len()可以返回序列中元素的数量
  • 序列支持切片操作

    5.1. 不可变序列

    • 字符串
    print(type(""))  # <class 'str'>
    
    • 元组
    t = 1, 2
    print(type(t))  # <class 'tuple'>
    
    • 字节串
    print(type(b""))  # <class 'bytes'>
    

    5.2. 可变序列

    • 列表
    print(type([]))  # <class 'list'>
    
    • 字节数组
    print(type(bytearray()))  # <class 'bytearray'>
    

6. 集合类型

  • 集合(可变)
print(type({1, 2}))  # <class 'set'>
  • 冻结集合(不可变)
print(type(frozenset()))  # <class 'frozenset'>

7. 映射类型

  • 字典
print(type({}))  # <class 'dict'>

8. 可调用类型

  • 函数(function)
def f(): pass

print(type(f))  # <class 'function'>
  • 方法(method)
class Test:
    def f(self): pass

t = Test()
print(type(t.f))  # <class 'method'>
print(type(Test.f))  # <class 'function'>

9. 模块

import builtins

print(type(builtins))  # <class 'module'>

10. 自定义类

class Test: pass

print(type(Test))  # <class 'type'>

11. 类实例

class Test: pass

t = Test()
print(type(t))  # <class '__main__.Test'>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值