Python 基础 格式化输出 现在需要我们录入我们身边好友的信息,格式如下: ------------ info of Alex Li ---------- Name : Alex Li Age : 22 job : Teacher Hobbie: girl ------------- end ---------------- 我们现在能想到的办法就是用一下方法: name = input('请输入姓名:') age = input('请输入年龄:') job = input('请输入职业:'
#格式化输出print("ang is a good time")str7="ong is a boy"num=10f=5.22313# %d(整数站位符) %s(字符串站位符) %f(浮点数站位符)# %f默认小数点后6位,%.3f精确到小数点后3位.默认会四舍五入print("num=",num,"f=",f)print("num= %d,str7=%s,f=%.9f" %(num,str7,f))''
a='this is a' b=a.replace('a','b') 字符串替换 c='this is %s %s' %('my','apple') d='this is {} {} ' .format('my','apple') e='this is {1} {0} ' .format('apple','my') 格式化输出,输出顺序 f='this is {whose} {fruit} ' .format(fruit='apple',whose='my') g='this is %(whos