When running, there is an error: syntax error: ‘break’ outside loop
Reason: break can only be used in for and while loops
Specific examples of error reporting
>>> def func(L): ... result = {} ... if not isinstance(L,list): ... print("Incorrect type") ... break ... File "<stdin>", line 5 SyntaxError: 'break' outside loop
Solution:
>>> def func(L): ... result = {} ... while not isinstance(L,list): ... print("Incorrect type") ... break ... >>> func([1,2,3,4]) >>> func("qwe") Incorrect type
Similar Posts:
- Run error: syntax error: ‘break’ outside loop
- [leetcode] 140. Word break II word split II
- [Solved] A label can only be part of statement and a declaratioin is not a statement
- Using join buffer (Block Nested Loop)
- AttributeError: ‘list’ object has no attribute ‘keys’
- python 3.6 socket tcp Connect TypeError: a bytes-like object is required, not ‘str’
- [swscaler @ …] deprecated pixel format used, make sure you did set range correctly
- Python uses decorator and reports error typeerror: ‘nonetype’ object is not callable ‘
- MySQL Executenamy: How to Write a batch of data