首页 > 编程知识 正文

python的占位符怎么用,python中字符串输出

时间:2023-05-06 13:34:05 阅读:12915 作者:1643

iwanttobeabletouseaplaceholderinastringthatalreadycontainsa % symbol.for instance,iwouldliketobeabletoiteratetooopenmultipenmultipltipltiplentiple

33558 www.example.com/blabla3blabla page=1

To do so,iwanttoreplacethenumber1bya placeholder (% d ),butthecodeseemstobeconfusedbythepresenceofthe % thatcomesbeforethetheplepleplthe

解决方案

You can escape % by doubling it:

' http://www.example.com/blabla; lablapage=%d'%(1,)

' http://www.example.com/blabla3blabla page=1'

Alternatively,use str.format () formatting instead:

' http://www.example.com/blabla3blabla page={ : d } '.format (1) )。

' http://www.example.com/blabla3blabla page=1'

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。