02 2019 档案
摘要:在Python中,异常也可以嵌套,当内层代码出现异常时,指定异常类型与实际类型不符时,则向外传,如果与外面的指定类型符合,则异常被处理,直至最外层,运用默认处理方法进行处理,即停止程序,并抛出异常信息。如下代码: try: try: raise IndexError except TypeError
阅读全文
摘要:众所周知,在python中,变量不需要事先声明,赋值后,即可调用使用。而调用的法则遵从LEGB法则,其中L为local,E为enclosing,G为Global,B为built-in,即变量首先在局部搜索,比如一个函数中,如果没有搜寻到,则继续在enclosing中搜寻,比如嵌套函数中更靠外侧的函数
阅读全文
摘要:1 """ 2 This script illustrate the usage of escape symbol %%. In general, it is used in mutil-formatted string. when a string is 3 formatted , %% can
阅读全文
摘要:(1)背景 python中,对于类(自定义类)的实例对象的默认显示既没有太大用处,也不美观。比如: 1 class adder: 2 def __init__(self,value=0): 3 self.data=value #初始化数据 4 def __add__(self,other): 5 s
阅读全文