【发布时间】:2019-01-04 08:28:38
【问题描述】:
我正在使用 Python 版本 3.6.4
我试图在 Jupyter Notebook 中编写基本的 Python 代码,但我发现我的代码表现得很有趣。
下面给出的代码按预期工作但是当我将第 4 行代码 print( x, '+', y, '=', x+y) 中的操作更改为 (+) 时,结果是 Error。
问题是为什么当操作符发生变化时,乘法工作正常而加法导致错误时会发生这种意外行为?
def fuc(x):
x = input('Enter the number:')
for y in range(1,11):
print( x, 'x', y, '=', x*y)
print(fuc(2))
【问题讨论】:
-
请勿发布文字图片。
-
请正确缩进您的代码。这在 Python 中至关重要。
-
这能回答你的问题吗? TypeError: Can only concatenate str (not "int") to str (simple Python programme)。简短的回答:定义了字符串和整数之间的乘法 - 返回与自身连接的字符串 int 时间。未定义字符串和 int 的添加
标签: python python-3.x