# 随机验证码
#random 随机的,胡乱的
import random a1='' for i in range(10): a2=random.randrange(0,6) if a2==2 or a2==4 or a2==0: a3=random.randrange(0,10) a1=a1+str(a3) else: a4=random.randrange(65,91) a5=chr(a4) a1=a1+a5 print(a1)
divmod函数
r=divmod(10,3)
print(r)
《《《(3,1)
# eval函数
a1=eval("a+23",{'a':37})
print(a1)
# 《《《60
# exec函数
exec('for i in range(11):print(i)')
# <<<<1,2,3,4,5,6,7,8,9,10
# filter(函数,可以迭代的对象)
 

 

def f1(s):
    if s > 3:
        return True
    else:
        return False


a = filter(f1, [1, 2, 3, 4, 5, 6, 7, 8, 9])
for i in a:
    print(i)


a=filter(lambda s:s>5,[1,2,3,4,5,6,7,8,9])
for i in a:
 print(i)
《《《《4,5,6,7,8,9

map函数
a = map(lambda s: s + 100, [1, 2, 3, 4, 5])
print(a)
for i in a:
    print(i)

《《《101,102,103,104,105

# hash函数 哈希值
dic={'aaaaa':'sdafsadfs','fsafwesd':'fdgdsgd','erwergfdg':'agsdgas'}
a=hash('aaaaa:sdafsadfs,fsafwesd:fdgdsgd,erwergfdg:agsdgas')
print(a)

《《《2253394742310548559

# isinstance判断某个对象是某个类创建的
li = [1, 2, 3, 4, 54]
a = isinstance(li, list)
b = isinstance(li, int)
print(a, b)
》》》》True False
# 迭代器,生成器
li = [1, 2, 3, 4, 54]
a=iter(li)
a1=next(a)
print(a1)
a2=next(a)
print(a2)
a3=next(a)
print(a3)
yield=>生成器关键字

<<<,1,2,3

# w,只写模式【不可读;不存在则创建;存在则清空内容;】
f=open('hk1.log','w')
f.write('1234')
f.close()
# x, 只写模式【不可读;不存在则创建,存在则报错】
f=open('hk2.log','x')
f.write('3546436')
f.close()
# a, 追加模式【不可读;   不存在则创建;存在则只追加内容;】
f=open('hk2.log','a')
f.write('0000000')
f.close()



 

 

 

 

# r ,只读模式【默认】
f = open('hk2.log', 'r')
a = f.read()
# f.write('0000000')
f.close()
b = bytes(a, encoding='utf-8')
print(b)


# wb 以二进制的方式写
f = open('hk1.log', 'wb')
# a = f.read()
f.write(bytes('中国',encoding='utf-8'))
f.close()

 

 

 

posted on 2018-02-06 14:41  1945775622  阅读(69)  评论(0)    收藏  举报