python总结(4)

1. python基础语法

a.注释:

# 单行注释:

''' : 三引号之间的内容就是多行注释

'''

b.变量:

即拿即用:不用提前声明

apple = 100

banana = 200

c.标识符与关键字

标识符:程序员定义的符号

关键字:

import keyword

print(keyword.kwlist)

d. 数据类型:

int: float

bool: True false

str:

定义: 引号之间的内容就是字符串

访问: 下标 (-1) while for [初始位置:终止位置:步长]

for i in str:

print(i)

字符串的函数操作:

i. find rfind index rindex count

ii.split splitline partition

iii.startswith endswith isspace isalpha isalnum isdigit

iv:upper lower title

v.center ljust rjust strip lstrip rstrip

vi. join

list:

定义: [int, str, bool, list, tuple, dict]

访问: 下标 while for [初始位置:终止位置:步长]

增删改查:

i. append insert extend

ii. del pop remove

iii. dic[下标] = new_value

iv: in not in index count

排序:

sort(reverse=True, key)

tuple:

定义:(int, str, bool ,list, tuple, dict)

访问: 下标 while for [初始位置: 终止位置: 步长]

查找: in not in index count

dict:

定义:{key: value}

访问:

dic[key]

dic.get()

增删改查:

增加:dic[new_key] = value

删除: clear() del dic[key]

修改: dic[key] = value

查找:

len(dic)

keys()

values()

items()

in not in index count

set:

定义: {int, bool, str}

特点: 唯一 无序

交集与并集: & |

e. 输入输出:

输入: input: 无论输入何种类型: 到程序中都以字符串显示

输出: print: %s %d format()

f.类型转换:

数据类型(变量名)

g.运算符:

/

//

**

=

and

or

not

2.逻辑语句

a. if

i.

if 条件:

pass

ii.

if 条件:

pass

else:

pass

iii.

if 条件:

pass

elif 条件:

pass

else:

pass

b. while

while 条件:

pass

while True:

pass

c. for

for i in 可迭代对象:

pass

d. break continue

3. 函数:

a. 定义与调用:

def 函数名(形式参数):

pass

函数名(实际参数)

b. 定义函数文档

def 函数名(形式参数):

'''

函数文档书写处

'''

pass

c. 缺省参数与不定长参数

def 函数名(age = 5)

pass

def 函数名(age,*args, **kwargs)

pass

d. 返回值:

return a, b, c, d

e. 递归回归函数:

函数自己调用字节

f. 列表推导式

[i for i in range(101)]

g.匿名函数:

lambda x, y: pass

4. 文件io

with open("", '') as f

f.read()

f.write()

f.seek()

os模块:

os.rename

os.remove

os.mkdir

os.rmdir

os.getcwd()

os.chdir

os.listdir()

5. 面向对象:

类:

a.组成:

类名

类属性:

类方法:

b.定义类:

class Cat(object):

pass

对象:

对象 = 类名()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小徐的记事本

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值