Python 读书

第一章

%d %s %f

数字和表达式

加减乘取模都可以直接输入

除需注意:

1/2=0.5

1/2.0=0.5 --有浮点按浮点计算

1//2=0 --整除

1.0/2.0=0.5

1.0//2.0=0.0   --取整后四舍五入

幂运算:

2**3 --2的3次方

长整形:数字结尾加L

十六和八进制:

0xAF

0o101

变量:

字母数字下划线,不能以数字开头

获取用户输入:input

函数:

pow(x,y)--次方 等值于 **

abs(x)--绝对值

round(x)--四舍五入

模块:

import math

math.floor(x) 向下取整

一次使用

form math import sqrt

sqrt(x)--开根号

特殊

import cmath

cmath.sqrt(-1)

叙述以J结尾

from decimal 十进制浮点型

decimal.Decimal()

_future_

raw_input()输入                    #input

raw_input("press <enter>")

注释:

# " "

字符串与转义字符:

字符串表示:

python会保存数字状态

str/repr

'''跨行原样输出

r开头原样输出类似c#@

unicode :

u ‘hello world’ --有问题

第二章

列表和元组

通用序列操作:

索引、分片、加、乘

索引:

f='hello'

f[0] --'h'

分片:

num=[1,2,3,4]下标0

num[1:3]--2,3

反向:num[-3:-1]

num[-3:] --最后位置省略

num[:3]  --起始位置省略

步长:[x:y:z]默认步长为1      --有问题[::z]

可以为负不能为0

同类型的序列相加

乘法:

数字*序列--重复N遍 

[None]*10 --10个空值

in测试存在包含

长度、最大最小

len、max、min

列表:

list('hey')-['h','e','y']

赋值:list[1]='w' --list('hwy')

删除:del list['1'] --list('hy')

分片赋值:

name=list('hey')

name[1:]=list['long']--name['hlong']

追加:append

统计:count

多值追加:extend --改变原始值

定位:index

插入:inser(3,‘内容’)

pop:移除并显示最后一位

移除:remove('内容')

反转:reverse()

排序:sort

比较:compar(x,y)

元组:

转换成元组

tuple('abc')--('a','b','c')

untitle

列表个数及元素的值都可以改变,元组看成只读的列表,不能被修改

untitle

bin(x) #转换成二进制

untitle

列表可变元组不可变

list

tuple

dict 

iter 迭代器

.copy()

.update()

.get()

setdefault()

.zip

0o752   --八进制

0b1010 --二进制

0x85a   --十六进制

--------------------------------------------------------

if **:**

elif **:**

else:**

while **:

**

for i in collections

print默认会添加换行,语句最后加(,)即可去除换行

---------------------------------------------------------

and   or   not  

字母数字下划线

长整形

布尔值

浮点值

复数

decimal.Decimal(*) 

'''*

*''' --三引号

if  elif  else

while

range()

xrange()

for x in temp

str=[x*x for x in range(4)]

for i in str

print i

access_mode  r/w/a/+/b  --读/写/添加/读写/二进制

try  except else  finally

__init__

import module_name

untitle

untitle

:符号

;分号

=等号

a=b=c=1

a,b=1,2

untitle

--doc--

untitle

del

untitle

type(*)

null对象None

[::] --切片

id()--唯一对象编号

untitle

isinstance

if * is *

untitle

untitle

untitle

可变:列表、字典

不可变:数字、字符串、元组

~ 取反

<< />> 左移右移

&、|、^

int/long/float/complex  转换

abs/coerce[返回两个数值的元组]/divmod[取整&取余]/pow[指数运算]/round   --内置数值运算

pow(x,y,z)x**y%z

untitle

oct()/hex()  --八进制/十六进制

chr(数值)/ord(字符)

unichr(num)

bool(*)

随机数

random 模块

randint() 两数之间的随机整数

uniform() 两数之间的随机浮点数

random()  0.0~1.0

ord()--字符序数

in /not in

untitle

untitle

untitle

untitle

原始字符串操作符 r/R

max/min

enumerate   --0 *

zip      --(*,*)

len

sorted

reverse

sum

dir(list)

append

count

extend

index

insert

pop

remove

upper

单元素元组 ('*',)

浅拷贝和深拷贝

copy.deepcopy()

strip() --空格

untitle

untitle

untitle

untitle

.keys()

.has_key()

.items()

.clear()

if __name__=='__main__'

.add()

.update()

.remove()

forzenset()

|=

&=

-=

^=

set()

* if * else *  --?:

break/continue

pass

iter()

next()

[* for * in * if *]

map()

filter()

lambda

open()

file()

read()

readline()

untitle

untitle

with  简化try-except-finally

raise 触发

assert 断言

sys.exc_info()

默认参数

可变长度参数

lambda 参数: 表达式

reduce()

globa  * 全局

闭包

counter()

import

form  import 

as 简化名称

load

__future__

__import__

reload()

class name  (父类/self):

__doc__

__base__

__module__

__init__

__new__

__del__

--静态

stacmethod()

classmethod()

GC()

isinstance(*,*) --对象是否是类的的实例

super()

vars()

--迭代器

randseq

anyIter

__slots__

property()

元类和metaclass 

callable()

compile()

eval()

exec()

input()

os.system()

os.open()

sys.exit()

SystemExit

os.kill()

@staticmethod   --静态方法

@classmethod --类方法

@property --特性

转载于:https://www.cnblogs.com/kinglongdai/p/8258914.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值