Mic*_*sny 5 python jupyter-notebook google-colaboratory
在这个程序中有一个故意的语法错误
import random
random.seed(16)
while True:
n = random.randrange(1,101)
print(n)
if n < 30: break
if n==20:
break
Run Code Online (Sandbox Code Playgroud)
在 google colab 上运行,!python test.py
产量符合预期
import random
random.seed(16)
while True:
n = random.randrange(1,101)
print(n)
if n < 30: break
if n==20:
break
Run Code Online (Sandbox Code Playgroud)
但是在 google colab 上作为 juypter 笔记本单元运行给出了输出
File "test.py", line 10
break
^
SyntaxError: 'break' outside loop
Run Code Online (Sandbox Code Playgroud)
在 juypter 笔记本中,程序运行直到离开 while 循环。我的理解是,单元格将保存在临时文件中,并使用标准 python 解释器执行。为什么执行方式不同?
归档时间: |
|
查看次数: |
481 次 |
最近记录: |