P40字符串格式化
作者:互联网
#__author__ = "cool"
#date = 2019/2/18 3:30
"""
作者格式:
__author__ = "cool"(名字)
date = 2019/2/18 3:30
在':'后传入一个整数,可以保证该域至少有这么多的宽度,用于美化表格时很有用:
>>> table = {'Jack':4127, 'Rose':4098, 'Peter':7678}
>>> for name, phone in table.items():
... print('{0:10} ==> {1:10d}'.format(name, phone))
...
Peter ==> 7678
Rose ==> 4098
Jack ==> 4127
"""
'''
普通输出
name = input("Name:")
age = input("Age:")
job = input("Job")
(薪水) salary = input("salary:")
print(name,age,job,salary)
格式化输出:%s
占位符%
%s == 一一对应的字符串 s = string
%d == 一一对应的数字 d = digit 整数
%f == 一一对应的小数 f = float 浮点数
print( "My name is %s" %("Alfred.Xue") )
'''
Name = input("Name:")
Age = int(input("Age:"))
Job = input("Job:")
Salary = input("salary:")
if Salary.isdigit(): #长的像不像数字,比如:100d,'200'
Salary =int(Salary)
else:
print("must input digit")
exit() #退出程序,exit()括号里可以跟东西,exit("must input digit")
msg = '''
--------info of %s-----------
Name:%s
Age:%d
Job:%s
Salary:%d
you will be retired in %s years
-------------end--------------
'''%(Name,Name,Age,Job,Salary,65-Age) #一一对应
print(msg)
#digit 翻译:数字
# nretired(退休年龄)
#告诉计算机,后面几个变量,进行关联,关联的关系是一一对应的
标签:Salary,格式化,Name,Age,name,print,字符串,input,P40 来源: https://www.cnblogs.com/Black-sail/p/11544110.html