1. 程式人生 > >python 基礎高階函式,正則表示式,md5加密演算法

python 基礎高階函式,正則表示式,md5加密演算法

import hashlib
hash=hashlib.md5()
hash.update("123456")
print hash.hexdigest()
random.random()浮點數  0.13634646
random.randint(1,10)  隨機整型所有包括10
random.randrange(1,2)
random.choice(a)a為列表

高階函式、、#zip(a, b)   #把兩個列表一一對應的來列印,還是比較有用的
map 
lambda
reduce
filter

def test():
return x+y
       print reduce(test(),range(101)) 連續求和過程

result=lambda x, y:x*y 
print result(x)

map(str,[1,2,3,45])=['1','2','3','45']
def fuck(x):
return x*x
print map(f,[1,2,3])=[1,4,9]   

卡表
import time 
start=time.clock()
for i in range (1000)
print  "deee"
print  time.clock() -start
  
import time
print time.time()#返回時間為秒
time.sleep(2)#時間沉睡緩衝
print time.asctime()
print time.ctime()#時間轉換,預設為本地時間
print time.localtime() #本地時間
print  time.strftime(" %Y-%m-%d  %H:%M:%S ",time.localtime()) #時間格式化
print time.strftime("%a %b %d %H:%M:%S",time.localtime())
寫模式----編譯
import re 
c=re.compile("^\d+")
res=c.match("ab1c")
if res:
print  res.group()
match只匹配第一位,search,findall()
[email protected]網易
[email protected] 新浪
import re
p=re.compile(r"^[a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-zA-Z]{2,}[        DISCUZ_CODE_0        ]quot;)
addr=raw_input("input your addr:")
res=p.match(addr)
if res:
    print "合法"
else:
    print "不合法"