初识Python(2)__Python 对象

Python 对象

python中一切皆为对象,所谓对象:我自己就是一个对象,我玩的电脑就是对象,坐着的椅子就是对象,家里养的小狗也是一个对象。。。。。。

我们通过描述属性(特征)和行为来描述一个对象的。比如家里的小狗,它的颜色,大小,年龄,体重等是它的属性或特征。它会汪汪叫,会摇尾巴等是它的行为。

我们在描述一个真实对象(物体)时包括两个方面:

它可以做什么(行为)

它是什么样的(属性或特征)。

在python中,一个对象的特征也称为属性(attribute)。它所具有的行为也称为方法(method) 

结论:对象=属性+方法 

 

对象三特性:

  1. 身份:唯一性身份标志,是该对象的内存地址,可用内建函数id()获得类型
  2. 类型:比如整型,浮点型,字符型等,可以用内建函数type()查看Python 对象的类型,type()返回的是对象而不是简单的字符串。例如:
>>> b = 1

>>> type(b)
<type 'int'>

 >>> type(int)
<type 'type'>

>>> type(type)
<type 'type'>

b的类型是int型, int的类型是‘类型’,type的类型还是类型。

             3. 值:对象表示的数据项

对象属性

属性:用来描述具体某个对象的特征的是属性,是静态的。比如:姚明身高2.6米多;小白的毛发是棕色的;二郎神额头上有只眼睛;

标准类型

  • 数字(分为几个子类型,其中有三个是整型)
  • 整型
  • 布尔型
  • 长整型
  • 浮点型
  • 复数型
  • 字符串
  • 列表
  • 元组
  • 字典

数据类型

存储模型

更新模型

访问模型

数字

Scalar原子类型

不可更改

直接访问

字符串

Scalar原子类型

不可更改

顺序访问

列表

Container容器

可更改

顺序访问

元组

Container容器

不可更改

顺序访问

字典

Container容器

可更改

映射访问

其他类型:

  • 类型
  • Null对象(None)
  • 文件
  • 集合/固定集合
  • 函数/方法
  • 模块

内部类型(暂时初步了解)

  • 代码:  参考:python中的代码对象
  • 帧:
  • 跟踪记录
  • 切片:当使用Python 扩展的切片语法时,就会创建切片对象。扩展的切片语法允许对不同的索引切片操作,包括步进切片, 多维切片,及省略切片。多维切片语法是 sequence[start1 : end1,start2 : end2], 或使用省略号, sequence[...,start1 :end1 ]. 切片对象也可以由内建函数 slice()来生成。步进切片允许利用第三个切片元素进行步进切片,它的语法为sequence[起始索引 : 结束索引 : 步进值]
  • 省略
  • Xrange

内建函数

  
 Built-in Functions   

abs()

divmod()

input()

open()

staticmethod()

all()

enumerate()

int()

ord()

str()

any()

eval()

isinstance()

pow()

sum()

basestring()

execfile()

issubclass()

print()

super()

bin()

file()

iter()

property()

tuple()

bool()

filter()

len()

range()

type()

bytearray()

float()

list()

raw_input()

unichr()

callable()

format()

locals()

reduce()

unicode()

chr()

frozenset()

long()

reload()

vars()

classmethod()

getattr()

map()

repr()

xrange()

cmp()

globals()

max()

reversed()

zip()

compile()

hasattr()

memoryview()

round()

__import__()

complex()

hash()

min()

set()

apply()

delattr()

help()

next()

setattr()

buffer()

dict()

hex()

object()

slice()

coerce()

dir()

id()

oct()

sorted()

intern()

参考官网:Built-in Functions

标准类型运算符和内建函数

Operator/Function

Description

Result

String

‘‘

String representation

st

cmp(obj1, obj2)

Compares two objects

 in

repr(obj)

String representation

st

str(obj)

String representation

st

type(obj)

Determines object type

 typ

Value comparisons

<

Less than

boo

>

Greater than

boo

<=

Less than or equal to

boo

>=

Greater than or equal to

boo

 ==

Equal to

boo

!=

Not equal to

boo

<>

Not equal to

boo

Object comparisons

is

The same as

boo

is not

Not the same as

boo

Boolean operators

not

Logical negation

boo

and

Logical conjunction

boo

or

Logical disjunction

boo

工厂函数

虽然看上去有点象函数, 实质上他们是类。当你调用它们时, 实际上是生成了该类型的一个实例。

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

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

原文地址:https://www.cnblogs.com/sunnyjiangjie/p/4079923.html