如何用%在Python里替换字符串的部分内容
1、新建一个空白的PYTHON文件。

2、先定义一个变量,然后把字符串内容改为另一个字符串
x = "Ben"
y = "My name is %s" %x
print(y)

3、可以把字符串里的改为整型数字。
a = 3
b = "The first number is %d" %a
print(b)

4、%f把整数改为有小数点的数值
c = 9
d = "You are the number %f guy" %c
print(d)

5、当然可以把有小数点的值改一下即可。
e = 8.987987234
f = "The answer is %f" %e
print(e)

6、如果不定义变量,其实也可以修改里面的内容的。
g = "The winner is %s" %"Alice"
print(g)

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。