python自动化web测试-"sprintf"函数

需求

不知道为什么,我用数值转换成字符串函数str()时,总是报莫名其妙的错,然后想到c语言中的格式化输出函数sprintf(),于是想,python应该也有类似的功能函数才对吧,于是:

代码

num = 1
string1= "hello"
s = str.format("%s-%d"%(string1,num))
#结果:s: "hello-1"

猜你喜欢

转载自blog.csdn.net/qq_40904479/article/details/105958697
今日推荐