1、基础格式
1 print("%s" %"hello")#字符串需要'' 2 3 print('%d' % 123)#格式化打印数字 digit 4 5 print('%f' % 2.5)#格式化打印浮点数 float 6 7 #%s 占位符
2、练习实例-------格式化打印员工信息
1 name = print("you name...") 2 age = print("you age..") 3 job = input("job...") 4 salary = input("you salary...") 5 6 message = '''------------info %s ----------------- 7 name = %s 8 age = %s 9 job = %s 10 salary = %s 11 you will be reretired %s years.... 12 -----------end--------------''' % (name, name, age, job, salary, 65-int(age)) 13 14 print(message) 15 #三引号除了注释还可以多行打印
3、判断输入的是否为数字
name = print("you name...") age = print("you age..") job = input("job...") salary = input("you salary...")#定义变量
if (age and salary).isdigit()#digit == 数字(判断输入的值是不是数字)
age = int(age)#int == 整数
salary = int(salary)
else:
print("you must input number age and salary...")
exit()#退出
message = '''------------info %s ----------------- name = %s age = %s 9 job = %s salary = %s you will be reretired %s years.... -----------end--------------''' % (name, name, age, job, salary, 65-int(age)) print(message) #三引号除了注释还可以多行打印