python:exec命令在jupyter notebook

时间:2017-09-13 02:14:05

标签: python

以下代码在pycharm中有效,但在jupyter notebook中生成错误。

请解释,为什么?

代码:

code = '''
x = 10 
y = 10 
print(x+y)
'''

exec(code)

错误:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-653-af591d5d8ad2> in <module>()
      7 '''
      8 
----> 9 exec(code)

TypeError: 'str' object is not callable

0 个答案:

没有答案