Python 极简核心:对象
1. 对象(object)
Python对象都拥有三个特性:身份(identity)、类型(Type)和值(Value)。
也就是说,任何一个Python对象都有一个身份、一个类型和一个值。
(Every object has an identity, a type and a value.)
概念区分:
-
对象
Python 中一切皆对象。 -
变量和对象的区别
变量是对象的引用。
In Python, variables are references to objects and any variable can reference any object.
赋值就是建立一个对象的引用。 -
值和对象的区别?
值只是对象的三个特性之一。
Every object has an identity, a type and a value.
2. 值(value)
2.1 Data type 数据类型
首先,要明白,Type(类型) 是对数据的一种划分。
这里主要列出的是Basic Data Types in Python,即Python基本数据类型。
Data type | example | |
---|---|---|
Number | ||
(数值) | ||
int 整型 | 10 | |
float 浮点数 | 2.0 | |
bool 布尔值 | True(1)、False(0) | |
complex 复数 | 2+3j | |
Composite Data Type | ||
(复合数据类型) | ||
String 字符串 | “hello” | |
List 列表 | [3, 2, 1] | |
Tuple 元组 | (1, 2, 3) | |
Dictionary 字典 | {‘a’:1, ‘b’:2, ‘c’:3} | |
Set 集合 | {3, 2, 2, 1, 0} | |
None(空值) |
注意:None 并不是0,None为特殊空值,而0是有意义的。
更全的分类是:
这部分可以参考:Basic Data Types in Python
2.2 Operator 操作符
Type 类型 | Operator 操作符 |
---|---|
Arithmetic operators | |
算术运算符 | +、-、*、/、%、//、** |
Comparison operators | |
比较运算符 | >、<、==、!=、>=、<= |
Logical operators | |
逻辑运算符 | and 、or、not |
Bitwise operators | |
位运算符 | &、|、~、^、>>、<< |
Assignment operators | |
赋值运算符 | =、+=、-=、*=、/=、…、 |
Special operators - dentity operators | |
特殊运算符 - 身份运算符 | is、is not |
Special operators - Membership operators | |
特殊运算符 - 成员运算符 | in、not in |