TypeError: cannot concatenate ‘str‘ and ‘int‘ objects说一个字符串自带的format方法
字符串被忽略的非常好用的format方法
很多时候我们会遇到像str和int此类无法与字符串相加的内容,这篇文章会简单介绍format的用法。
代码展示
// An highlighted block
print 'ss'+1;
#报错TypeError: cannot concatenate 'str' and 'int' objects
print 'ss{}'.format(1)
输入:ss1
非常简单的用法,字符串中{}的位置就是插入数据的位置,format()括号中就是插入的数据。代码中将1插入
原创
2022-02-25 17:40:33 ·
456 阅读 ·
0 评论