formatter ='{} {} {} {}'print(formatter.format(1,2,3,4))print(formatter.format('one','two','three','four'))print(formatter.format(True,False,True,False))print(formatter.format(formatter,formatter,formatter,formatter))print(formatter.format('Try your','Own text here''Maybe a poem''Or a song about fear'))
报错如下
print(formatter.format(
IndexError: Replacement index 2 out of rangefor positional args tuple
代码修正后:
formatter ='{} {} {} {}'print(formatter.format(1,2,3,4))print(formatter.format('one','two','three','four'))print(formatter.format(True,False,True,False))print(formatter.format(formatter, formatter, formatter, formatter))print(formatter.format('Try your','Own text here','Maybe a poem','Or a song about fear',))
输出:
1234
one two three four
TrueFalseTrueFalse{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}
Try your Own text here Maybe a poem Or a song about fear
进程已结束,退出代码0
Tips:
报错原因:‘Own text here’, ‘Maybe a poem’, ‘Or a song about fear’,后面丢失了“,”