字符串格式化
a = "------------- 我爱涛 -------------"b = "name:"c = "age:"d = "job:"e = "-------------- 结束 -------------"name = input("name")age = input("age")ob = input("job")print(a + "\n" + b + name + "\n" + c + age + "\n"+ d + job + "\n" +e)
s = """ ------------- 我爱涛 -------------name:%sage:%sjob:%s-------------- 结束 -------------"""name = input("name")age = int(input("age"))job = input("job")print(s%(name,age,job))
num = input('学习进度:')s11 = "大哥黑的学习进度为:%s %%"print(s11%(num))#扩展s11 = "大哥黑的学习进度为:%s"print(s11%("不错"))
name = input(">>>")s = f"小哥哥你的名字{name}"print(s)#活学扩展s = f"小哥哥你的名字{input('>>>')}"print(s)
s = f"{1}{2}{3}"print(s)# 输出结果 123
- %s 是占的字符串类型的位置
- %d 是占的数字类型的位置
- %% 转换成普通的%号
- 按照位置顺序传递,占位和补位必须要一一对应