Getting started N day
math general math module
cmath complex number math module
random The random number module
random.radint (m,n) generates a random number from m to n.
random.random generates a random number from 0 to 1, with the left closed and right open interval, less than 1
random.shuffle (sequence) shuffles the list Order
random.choice(sequence) randomly
select an element in a list random.choices(sequence, k=N) randomly select an element N times, one at a time
os file/directory method module
Novice tutorial address:
https://www.runoob.com/python3/python3-os-file-methods.html
os.chdir (path) Modify the path corresponding to the specified path to the current py file location the path
os.getcwd () Gets the current file absolute path
os.path.basename (path) Gets the path to the file name
if os.path.exists (path) to determine the path specified file exists
json module
re regular module
sys.exit() exit thread early
turtle drawing module
csv csv file operation
smtplib mail sending
print(random.random() * 100) # 产生0~100的随机小数
print(random.random() * 50 + 50) # 产生50~100的随机小数
str1 = 'abc'
print(random.choices(str1, k=2)) # ['c', 'c']
print(os.getcwd()) # E:\Python2004\01语音基础\day15-常用模块
print(os.path.basename(r'E:\Python2004\01语音基础\day15-常用模块.py'))
# day15-常用模块.py 获取指定路径中的文件名
print(os.path.basename(r'E:\Python2004\01语音基础')) # 01语音基础
turtle.setup(600, 800) # 创建一个600*800的画布
-
Timestamp:
in seconds to express GMT at 0:00:00 on January 1, 1970 of the time difference, a difference of eight hours and Beijing
stored timestamp information more than the direct saving time to save memory
on the timestamp Encryption is much more convenient than encrypting string time.
time() Get the timestamp of the current timet1 = time.time() # 1603093091.0485027 second = 1603093091.0485027 t2 = time.localtime() print(t2) # time.struct_time(tm_year=2020, tm_mon=10, tm_mday=19, tm_hour=16, tm_min=4, tm_sec=30, tm_wday=0, tm_yday=293, tm_isdst=0) t3 = time.localtime(second) print(t3) # time.struct_time(tm_year=2020, tm_mon=10, tm_mday=19, tm_hour=15, tm_min=38, tm_sec=11, tm_wday=0, tm_yday=293, tm_isdst=0) print(time.localtime(0)) # time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=8, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=1, tm_isdst=0) # strftime() t = time.time() # 1603093091.0485027 second = 1603093091.0485027 t2 = time.localtime(t) t3 = time.strftime('%Y-%m-%d %H:%M:%S', t2) print(t3) # 2020-10-19 16:19:07 # strptime() s1 = '2020/10/19' s2 = time.strptime(s1, '%Y/%m/%d') print(s2) # time.struct_time(tm_year=2020, tm_mon=10, tm_mday=19, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=0, tm_yday=293, tm_isdst=-1)
- The hashlib module mainly provides algorithms related to hash digest (hash encryption) to encrypt data
- The encryption result is irreversible (the original text cannot be obtained through the ciphertext/summary)
- The same data passes the same algorithm, and the result after encryption is the same
Application scenarios of hash digests of the same length after different data is encrypted by the same algorithm :- Password save
- Verification of data integrity
# 根据算法创建hash对象 hash1 = hashlib.md5() # 添加需要生成摘要(密文的数据) hash对象.update(数据的二进制) mima = '123456' hash1.update(mima.encode(encoding='utf-8')) # 生成摘要 dig = hash1.hexdigest() print(dig) # e10adc3949ba59abbe56e057f20f883e hash2 = hashlib.sha1() mima = '123456' hash1.update(mima.encode(encoding='utf-8')) # 生成摘要 dig = hash1.hexdigest()