Open eeechoo opened 5 years ago
while True:
print(1)
# IndentationError: expected an indented block
a = 1
if a === 3:
print(a)
# SyntaxError: invalid syntax
print(a)
a = 2
# NameError: name 'a' is not defined
def foo():
print(a)
a = 2
foo()
# UnboundLocalError: local variable 'a' referenced before assignment
def foo(end):
a = 0
while True:
if a == end:
break
yield a
a += 1
gene = foo(2)
print(next(gene))
print(next(gene))
print(next(gene))
# StopIteration
# 在命令行中运行,然后按下 Control + C
while True:
print(1)
# KeyboardInterrupt
EOF 是什么 stackoverflow回答
什么会引起 EOF
while True:
a = input("echo: ")
print(a, type(a))
hierarchy Python3.7 windows64
IOError = WindowsError
Warning
1. SyntaxError
这段代码运行时仍然会报 SyntaxError,好像 try except 语句并未能捕获这个异常,这是为什么呢? stackoverflow回答 stackoverflow回答 这里的两个回答涉及 python 解释器的工作原理,我对这里不是太清楚。
2. Exceptions
Python 3.7 exception hierarchy