%(格式化字符串)幾種格式的使用


%(格式化字符串)

name = input('請輸入姓名:')
age =input('請輸入年齡: ')
height =input('請輸入身高: ')
msg ="我叫%s 今年%s  身高%s" % (name,age,height)
print(msg)
Name = input('請輸入姓名:')
Age =input('請輸入年齡: ')
job =input('請輸入工作: ')
Hobbie=input('你的愛好: ')
msg = '''——————info of %s——————
Name  :%s
Age   :%d
job   :%s
Hobbie:%s
————————end——————————'''% (Name,Name,int(Age),job,Hobbie)
print(msg)
name = input('請輸入姓名:')
age =int(input('請輸入年齡: '))
height =input('請輸入身高: ')
msg ="我叫%s 今年%s  身高%s,學習進度3%%s" % (name,age,height) #想要格式化輸出加一個%,是后面的%
print(msg)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM