python基础04
1,集合
list允许重复的集合,修改
tuple允许重复的集合,不修改
dict
set不允许重复的列表
2,三元运算
if i==1:
name="alex"
else:
name="eric"等同于
name="alex" if i==1 else "eric"
3,生成随机验证码
import random temp="" for i in range(50): rad=random.randrange(65,91) c=chr(rad) temp=temp+c print(temp)
4,文件操作的几个模式
r 只读模式 f = open('hello.txt','r')
w 只写模式,不可读,若不存在则创建
x 只写模式,不可读,不存在则创建,存在则报错
a 追加模式,可读,不存在则创建,存在则追加内容
r+读写(可读,可写)
w+写读(可读,可写)
x+写读(可读,可写)
a+写读(可读,可写)

浙公网安备 33010602011771号