02 2019 档案

摘要:在Python中,异常也可以嵌套,当内层代码出现异常时,指定异常类型与实际类型不符时,则向外传,如果与外面的指定类型符合,则异常被处理,直至最外层,运用默认处理方法进行处理,即停止程序,并抛出异常信息。如下代码: try: try: raise IndexError except TypeError 阅读全文
posted @ 2019-02-20 20:53 JohnYang819 阅读(9284) 评论(0) 推荐(0) 编辑
摘要:众所周知,在python中,变量不需要事先声明,赋值后,即可调用使用。而调用的法则遵从LEGB法则,其中L为local,E为enclosing,G为Global,B为built-in,即变量首先在局部搜索,比如一个函数中,如果没有搜寻到,则继续在enclosing中搜寻,比如嵌套函数中更靠外侧的函数 阅读全文
posted @ 2019-02-18 20:09 JohnYang819 阅读(539) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2019-02-07 14:39 JohnYang819 阅读(159) 评论(0) 推荐(0) 编辑
摘要:(1)背景 python中,对于类(自定义类)的实例对象的默认显示既没有太大用处,也不美观。比如: 1 class adder: 2 def __init__(self,value=0): 3 self.data=value #初始化数据 4 def __add__(self,other): 5 s 阅读全文
posted @ 2019-02-07 14:27 JohnYang819 阅读(428) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示