我使用 google colab,最近它非常不稳定且容易出错,即使没有。这是colab的特点吗?

I use google colab, and recently it has been extremely erratic and error prone ,even when there aren't any. Is this a characteristic of colab?

我在 colab 中使用了一个新笔记本,同样的代码工作得很好。这可能是与 colab 相关的问题。 1: https://i.stack.imgur.com/zzamQ.png 不过我还是很好奇为什么会这样。

def function(a,b,c): 
  temp = a

  for i in (b,c):

    if i > temp:

      temp = i

  return temp


function(43,54,12)

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-127543af6285> in <module>()
----> 1 function(43,54,12)

NameError: name 'function' is not defined

[1]: https://i.stack.imgur.com/atmRn.png

function的调用应该在函数声明和定义之后完成,因为解释器首先解释函数,然后评估函数调用。

确保在定义 function 本身之后调用 function(43, 54, 12)


还要确保在按下 Tab 键时将缩进从 2 space 更改为 4 spaces,方法是进入 Tools > Setting > Editor 并更改:


除了安装新包后,还需要重启内核。有时只需重新启动内核即可刷新环境并修复问题。