python_字符串的格式化输出

name = input("Name:")
age = int(input("Age:")) input: 输入的内容默认为字符串格式
job = input("Job:")
salary = input("Salary:")

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

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

print(msg)


st='hello kitty {name} is {age}'
print(st.format(name='alex',age=37)) # 格式化输出的另一种方式 hello kitty alex is 37
原文地址:https://www.cnblogs.com/lokerx/p/10681747.html