码迷,mamicode.com
首页 > 其他好文 > 详细

字符串 格式化输出

时间:2018-06-18 14:30:23      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:NPU   浮点数   job   put   格式化   end   ring   lse   ret   

name = input("name:")
age = int(input("age:"))
job = input("job:")
salary = input("salary:")

if salary.isdigit(): #长的像不像数字,比如200d。“200”
salary = int(salary)
# else:
# #print("must input digit")
# exit("must input digit")# 退出程序
#

msg = ‘‘‘
------------info of %s-----------
Name: %s
Age : %d
Job : %s
Salary: %f
You will be retired in %s vears
------------ end ---------------
‘‘‘ % (name,name,age,job,salary,65-age)
print(msg)

# 字符串格式化输出
# 占位符 %s s = string
# %d d = digit 整数
# %f f= float 浮点数,约等于小数。

字符串 格式化输出

标签:NPU   浮点数   job   put   格式化   end   ring   lse   ret   

原文地址:https://www.cnblogs.com/fy414371/p/9195077.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!