Python之格式化输出
常用的格式化符号:
%s 对应的是字符串类型(str)s = string
%d 对应十进制整数型的(int)d = digit
%f 对应浮点数(float)当前理解成小数
%r 对应字符串(repr)
示例:
"""
time: 2019/5/20 9:26
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
name = input("输入姓名:")
age = int(input("输入年龄:"))
job = input("输入工作类型:")
salary = input("输入薪资:")
msg = """
---------------- info of %s ----------------------
Name:%s
Age:%s
Job:%s
Salary:%s
You will be retired in %s years
--------------- end --------------------------------------
"""%(name,name,age,job,salary,65-age)
print(msg)
代码输出结果:
---------------- info of 张三 ----------------------
Name:张三
Age:22
Job:计算机应用与技术
Salary:15000
You will be retired in 43 years
--------------- end --------------------------------------
Process finished with exit code 0