Python TypeError:无法将“int”对象隐式转换为str

Python TypeError:无法将“int”对象隐式转换为str,python,Python,我是个新手。我已经开始在Ubuntu上使用python。我的版本是Python3.4 我编写了以下代码&出现错误: >>> g=input("Enter number here: ") Enter number here: 43 >>> g+7 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: Can't convert

我是个新手。我已经开始在Ubuntu上使用python。我的版本是Python3.4 我编写了以下代码&出现错误:

>>> g=input("Enter number here: ")
Enter number here: 43
>>> g+7
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Can't convert 'int' object to str implicitly
>>> a= input("Enter:")
Enter:43
>>> a +32
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Can't convert 'int' object to str implicitly
>>> a+32
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Can't convert 'int' object to str implicitly
>>> 
任何人都可以帮忙吗?

输入将返回一个str,您必须将其转换为int才能对其进行数值运算

>>> g = int(input('enter a number:'))
enter a number: 5

>>> g + 7
12
转换前

转换后

尝试:

。。。以及:

>>> int(a) + 32
也许你可以试试这个。。。 在Python3.4中,输入被转换为字符串。你可以调用g,结果是'43'…这个字符串。。 所以转换成整数

>>> g = int(input('enter a number:'))
enter a number: 5

>>> type(g)
<class 'int'>
>>> int(g)+7
>>> int(a) + 32
>>> g=input("Enter number here: ")
Enter number here: 43
>>> g+7
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Can't convert 'int' object to str implicitly
>>> 
>>> g
'43'
>>> int(g)+7
50
>>>