string_format
运行代码:
#!/usr/bin/env python ##声明python所在位置 # -*- coding:utf-8 -*- #声明使用utf-8中文 name = input("Name:").strip() #输入name,去除空格 age = int(input("Age:")) #输入age job = input("Job:").strip() #输入job,去除空格 msg = ''' #定义变量 Information of %s: Name:%s Age:%s Job:%s ''' %(name,name,age,job) #声明%变量 print(msg)
# %d 数字
# %f 浮点
#.strip()去空格
运行结果:
1 C:\Users\Meng\AppData\Local\Programs\Python\Python36\python.exe C:/Users/Meng/PycharmProjects/day1/string_format.py 2 Name:mike 3 Age:29 4 Job:IT 5 6 Information of mike: 7 Name:mike 8 Age:29 9 Job:IT 10 11 12 Process finished with exit code 0

浙公网安备 33010602011771号