当前位置:首页 > Python教程 > python技巧

Python 百分号字符串拼接

# %s可以接收一切 %d只能接收数字
msg = ‘i am %s my hobby is %s‘ %(‘lhf‘,‘alex‘)
print msg
msg2 = ‘i am %s my hobby is %d‘ %(‘lhf‘,1)
print msg2

#打印浮点数
tpl ="percent %.2f" %99.976 #截取几位
print tpl
tpl2 = "i am %(name)s age %(age)d" %{"name":"alex","age":18}
print  tpl2

msg3 = ‘i am %(name)-60s‘ % {"name":"wangyue"}
print msg3

print (‘root‘,‘x‘,‘6‘,sep=‘:‘)

 

原文:https://www.cnblogs.com/wangyue0925/p/8930999.html


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!