【问题标题】:TypeError: 'str' object is not callable - Copied the code directly from the source and got this error. Why?TypeError: 'str' object is not callable - 直接从源代码复制代码并收到此错误。为什么?
【发布时间】:2020-05-25 22:10:51
【问题描述】:

    x = np.linspace(0,5,11)
    y = x ** 2
    plt.plot(x,y)
    plt.plot(x, y, 'r') # 'r' is the color red
    plt.xlabel('X Axis Title Here') #Program stops here and prints str is not callable. 
    plt.ylabel('Y Axis Title Here')
    plt.title('String Title Here')

我从源代码(来自在线课程的 Jupyter 笔记本)复制并粘贴了代码,但出现错误:str is not callable。为什么?

【问题讨论】:

  • 似乎 xlabel 被设置为 Jupyter 笔记本中的字符串。你能检查整个笔记本,看看是否有任何地方 xlabel 被设置为字符串?另外,你在笔记本的任何地方有任何导入语句吗?如果有,是什么?
  • 您提供的代码运行良好。
  • 谢谢大家。阅读我的答案。出于某种未知原因,我关闭了笔记本,重新打开,运行程序,它运行了。在技​​术如此变化无常的情况下,人类如何能够向月球发射火箭并​​返回,我永远无法理解。

标签: python string jupyter-notebook


【解决方案1】:

我不明白为什么,但是在我关闭笔记本并重新打开它并运行程序后,它会生成 x 和 y 标签以及标题。 IOW,程序运行得很好,没有错误。 这是第二次发生这种情况,“this”是程序返回错误;我关闭并重新打开笔记本,然后运行程序,它就可以工作了。

猜你喜欢
  • 2019-11-27
  • 2020-11-12
  • 2020-12-15
  • 2013-05-28
  • 2022-11-20
  • 2018-01-26
  • 2019-11-11
  • 1970-01-01
  • 2021-09-15
相关资源
最近更新 更多