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