python 字符串变量替换

>>> ac="mmjj"
>>> aaa="adfbvbad{}".format(ac)
>>> aaa
'adfbvbadmmjj'
>>> aaa="adfbvbad{}aaa{}".format(ac)
Traceback (most recent call last):
  File "<pyshell#12>", line 1, in <module>
    aaa="adfbvbad{}aaa{}".format(ac)
IndexError: tuple index out of range
>>> aaa="adfbvbad{}aaa{}".format(ac,ac)
>>> aaa
'adfbvbadmmjjaaammjj'
>>> 

 

posted @ 2022-11-27 09:41  myrj  阅读(149)  评论(0编辑  收藏  举报