python中信息拼接打印
Posted 清晨日光
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python中信息拼接打印相关的知识,希望对你有一定的参考价值。
#%s是点位符 s--string
name = input("name:")
age = input("age:")
job = input("job:")
salary = input("salary:")
info=\'\'\'
-----info of0\'\'\'+name +\'\'\'----
Name:\'\'\'+name+\'\'\'
Age:\'\'\'+age+\'\'\'
Job:\'\'\'+job+\'\'\'
Salary:\'\'\'+salary
print(info)
name = input("name:")
age = int (input("age:"))
print(type(age))
#print(type(age),type(str(age))) 再转换成str
job = input("job:")
salary = input("salary:")
info1=\'\'\'
-----info of1 %s----
Name:%s
Age:%d
Job:%s
Salary:%s
\'\'\' % (name,name,age ,job,salary)
print(info1)
info2=\'\'\'
-----info of2 {_name}----
Name:{_name}
Age:{_age}
Job:{_job}
Salary:{_salary}
\'\'\'.format (_name=name,_age=age,_job=job,_salary=salary)
print(info2)
info3=\'\'\'
-----info of3 {0}----
Name:{0}
Age:{1}
Job:{2}
Salary:{3}
\'\'\'.format (name,age,job,salary)
print(info3)
运行结果:
以上是关于python中信息拼接打印的主要内容,如果未能解决你的问题,请参考以下文章
python用变量拼接并打印一句话。我叫xxx,我的年龄是28岁身高1.83?