字符串拼接:字符串+字符串/数字

字符串拼接

两个字符串相加

str1 = 'hello'
str2 = 'world'
str_11 = str1 + str2
str_12 = str1 +' '+ str2
print('str_11:',str)
print('str_12:',str_1)
结果:
str_11: helloworld
str_12: hello world``

字符串加数字

str1 = 'hello'
str2 = 'world'
str_11 = str1 + str2
str_1 = str1 +' '+ str2
for i in range(8):
    str_2 = str_11 +" "+ str(i+1)
    print(str_2)
run result:
helloworld 1
helloworld 2
helloworld 3
helloworld 4
helloworld 5
helloworld 6
helloworld 7
helloworld 8

当出现这种错误时——TypeError: ‘str’ object is not callable
是由于前面将str定义为一个变量了,造成变量名与函数的冲突,将变量名改掉就好

TypeError: 'str' object is not callable

你可能感兴趣的:(python,basis,python,string,pycharm)