1,当函数没有显式地返回一个值时,例如没有执行到return object语句就结束了,他就返回None。
2 finally会自动的重新引发异常。
3.with语句目标的应用场景:保证共享资源的唯一分配,并在任务结束时释放它。比如文件(数据、日志、数据库等等)、线程资源、简单同步、数据库连接等等。类似于try...except但简化代码。
with context_expr [as var]:
with_suite
with语句仅能工作于支持上下文管理协议(context management protocol)的对象,即只有内建了‘上下文管理’的对象才可以和with一起工作。
支持with语句的有:
file decimal.Context、 thread.LockType、 threading.Lock、 threading .RLock、 threading.Condition、 threading.Semapjore、 threading.BoundedSemaphore.
4 for循环有next()调用和对StopIteration的处理。