【发布时间】:2014-11-15 07:07:40
【问题描述】:
代码:
String1 = " Is right"
g = lambda x: x ** 2
print(g(8)) + str(String1)
错误:
Traceback (most recent call last):
File "C:/Users/Computer/Desktop/Testing.py", line 3, in <module>
print(g(8)) + str(String1)
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
代码2: 我也试过添加这个:
g = lambda x: x ** 2 + " Should be right!"
print(g(8))
错误:
Traceback (most recent call last):
File "C:/Users/Computer/Desktop/Testing.py", line 2, in <module>
print(g(8))
File "C:/Users/Computer/Desktop/Testing.py", line 1, in <lambda>
g = lambda x: x ** 2 + " Should be right!"
TypeError: unsupported operand type(s) for +: 'int' and 'str'
我用 int 和 str 试过了,但还是有问题?
另外在修复时,请解释固定代码的工作原理:) 我不想只是复制固定行
【问题讨论】:
标签: python string python-3.x int typeerror