pycharm小技巧,一般情况下都需要在代码前注释以下作者以及创建日期
但是如何让软件默认生成呢?
格式化输出
可以用占位符
%s string的缩写
#__author:Administrator #date:2017/9/8 name = input("Name:") age = input("Age:") job = input("Job:") salary = input("Salary:") print(name,age,job,salary) msg = ‘‘‘ -------info of %s------ Name: %s Age: %s JOb: %s Salary: %s -------end------ ‘‘‘ % (name,name,age,job,salary) print (msg)
#__author:Administrator #date:2017/9/8 name = input("Name:") age = int(input("Age:")) job = input("Job:") salary = input("Salary:") print(name,age,job,salary) 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)
#__author:Administrator #date:2017/9/8 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") print(name,age,job,salary) 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)
全部注释:ctrl+/
%d就表示必须输入数字
占位符:
%s s = string
%d d = digit 整数
%f f = float 浮点数,约等于小数
时间: 2024-10-15 03:13:25