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

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

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

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

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

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