运行时报错:SyntaxError: 'break' outside loop。

原因:break只能在for和while循环中使用。

 

报错的具体例子

>>> def func(L):
...     result = {}
...     if not isinstance(L,list):
...         print("类型不正确")
...         break
...
  File "<stdin>", line 5
SyntaxError: 'break' outside loop

解决方法:

>>> def func(L):
...     result = {}
...     while not isinstance(L,list):
...         print("类型不正确")
...         break
...
>>> func([1,2,3,4])
>>> func("qwe")
类型不正确

 

相关文章:

  • 2021-11-27
  • 2022-12-23
  • 2022-12-23
  • 2021-05-20
  • 2022-01-13
  • 2022-12-23
  • 2021-11-09
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-18
相关资源
相似解决方案