import hashlib
MD5=hashlib.md5()
MD5.update('how are you'.encode('utf-8'))
MD5.update(b'how are you')#和上面一行功能一样
print(MD5.hexdigest())如果数据量很大,可以分块多次调用update(),最后计算的结果是一样的:import hashlib
md5 = hashlib.md5()
md5.update('how to use md5 in '.encode('utf-8'))
md5.update('python hashlib?'.encode('utf-8'))
print(md5.hexdigest())
import hashlibsha1 = hashlib.sha1()
sha1.update('how to use sha1 in '.encode('utf-8'))
#sha1.update(b'how to use sha1 in ')sha1.update('python hashlib?'.encode('utf-8'))
print(sha1.hexdigest())