我有这个python程序,它将字符串添加到整数:
a = raw_input("Enter a: ")
b = raw_input("Enter b: ")
print "a + b as strings: " + a + b
a = int(a)
b = int(b)
c = a + b
str(c)
print "a + b as integers: " + c
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
Python: TypeError: cannot concatenate 'str' and 'int' objects
Run Code Online (Sandbox Code Playgroud)
如何将字符串添加到整数?
嗨我有一个问题我不明白为什么我有一个类型错误请解释它是什么以及我如何解决它提前谢谢!
abb = raw_input("Abbreviation: ")
text = raw_input("Text: ")
text = text.lower().split()
abb = abb.lower().split
list1 = []
i = 0
j = 0
while i < len(text):
for i in range(len(text)):
if text[i].startswith(abb[0]):
list1.append(text[i])
for i in range(len(text)):
if text[i].startswith(abb[1]):
list1.append(text[i])
for i in range(len(text)):
if text[i].startswith(abb[2]):
list1.append(text[i])
Run Code Online (Sandbox Code Playgroud)