1. 程式人生 > >%(格式化字串)幾種格式的使用

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

%(格式化字串)

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)