time库:
import time
print(time.ctime())
'''
strftime(tpl,ts),tpl是格式化模板字符串,用来定义输出效果
ts是计算机内部时间类型变量
'''
t=time.gmtime()
print(time.strftime("%Y-%m-%d %H:%M:%S",t))
import time
start=time.perf_counter()
end=time.perf_counter()
print(end-start)
import time
for i in range(101):
print("{:3}%".format(i),end=" jk")
time.sleep(0.01)
import time
for i in range(101):
print("\r{:3}%".format(i),end=" jk")
time.sleep(0.01)
import time
scale=50
print("执行开始".center(scale//2,'-'))
start=time.perf_counter()
for i in range(scale+1):
a='*'*i
b='.'*(scale-i)
c=(i/scale)*100
dur=time.perf_counter()-start
print("\r{:^3.0f}%[{}->{}]{:.2f}s".format(c,a,b,dur),end='')
time.sleep(0.1)
print("\n"+"执行结束".center(scale//2,'-'))
逻辑符号:and(与) or(或) not(非)
异常处理:
print 默认输出是换行的,如果要实现不换行需要在变量末尾加上 end=""。
height,weight=eval(input("请输入身高和体重: "))
bmi=weight/pow(height,2)
print("BMI数值为:{:.2f}".format(bmi))
who,nat='',''
if bmi<18.5:
who,nat='偏瘦','偏瘦'
elif 18.5<=bmi<24:
who,nat='正常','正常'
elif 24<=bmi<25:
who,nat='正常','偏胖'
elif 25<=bmi<28:
who,nat='偏胖','偏胖'
elif 28<=bmi<30:
who,nat='偏胖','肥胖'
else:
who,nat='肥胖','肥胖'
print("BMI指标为:国际'{0}',国内'{1}'".format(who,nat))
循环结构:
s='Python123'
for c in s:
print(c,end='')
print("\n")
for item in [123,'py',456]:
print(item,end=',')
random库:
import random
random.seed(10)
print(random.random())
print(random.randint(10,100))
print(random.randrange(10,100,10))
print(random.uniform(10,100))
|