4 格式化输出

>>> name=input("input name:")         
input name:Li ming

>>> sex=bool(input("input sex(True,False):"))
input sex(True,False):True

>>> scale=float(input("input scale (0.x):"))  #要求输入分数,强制为float 
input scale (0.x):0.7


>>> print("name:%s, sex:%d"%(name,sex))      # 与c不同的是,中间用 % ,后面变量括号扩住
name:Li ming, sex:1


>>> print("scale:%.2f%%"%(scale*100)) #输入 % 需要用 %% .2f 输入小数点后面2位,同c
scale:70.00%


 

posted @ 2020-06-07 22:11  abel2020  阅读(109)  评论(0编辑  收藏  举报