"""
字符串格式化
"""
name = 'Jenny'
age = 30
x = "my name is %s, age is 20" % name
print(x)
x1 = "my name is %s, age is %s" % (name, age)
print(x1)
# 第二种
y = "my name is {}, age is {}".format(name, age)
print(y)
# 第三种 f-string # python3.6以后新语法
z = f"my name is {name}, age is {age}"
print(z)
输出:
![](/i/l/?n=23&i=blog/674828/202301/674828-20230111175835537-1916013193.png)
推荐最后一种方法
标签:格式化,name,Python,age,接口,字符串,print,my From: https://www.cnblogs.com/jiangkeji/p/17044566.html