【接口自动化测试】Python基础-字符串格式化

"""
字符串格式化
"""
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)

输出:

 

 

 

 推荐最后一种方法

 

posted @ 2023-01-11 18:00  Jenny测试开发  阅读(15)  评论(0编辑  收藏  举报