摘要: 魔法方法总是被双下划线包围,例如__init__ 魔法方法是面向对象的Python的一切,如果你不知道魔法方法,说明你还没有意识到面向对象Python的强大 魔法方法的‘魔力’体现在他们总能够在适当的时候被调用 1.__init__(self[,...]) 返回一个None对象 类在实例化的时候默认 阅读全文
posted @ 2017-09-12 20:33 110528844 阅读(204) 评论(0) 推荐(0) 编辑
摘要: 1. issubclass(class,classinfo) 一个类被认为是其自身的子类 classinfo可以是类对象组成的元组,只要class与其中任何一个候选类的子类,则返回True 其他情况TypeError 2. isinstance(object, classinfo) 1.如果第一参数 阅读全文
posted @ 2017-09-12 14:10 110528844 阅读(212) 评论(0) 推荐(0) 编辑
摘要: 继承 被继承的类称为基类/父类或超类 继承者称为子类 class DerivedClassName(BaseClassName): ...... 如果子类定义与父类同名的方法或属性,则会自动覆盖对应的方法或属性 运行结果 [fengjunjie@localhost ~]$ python3 test. 阅读全文
posted @ 2017-09-11 20:26 110528844 阅读(171) 评论(0) 推荐(0) 编辑
摘要: 对象 = 属性 + 方法 self是什么东西 this指针 python的魔法方法 公有和私有 私有的实现 name mangling 名字改编,名字重整 伪私有 类对象 运行结果: [fengjunjie@localhost ~]$ python3 test.pygreen我们正在很努力的向前爬. 阅读全文
posted @ 2017-09-11 17:55 110528844 阅读(203) 评论(0) 推荐(0) 编辑
摘要: 1.要么怎样,要么不怎样 if else 2.干完了能怎样,干不完就别怎样 for while else else只循环完成后执行,如果循环使用了break语句跳出了循环,else语句是不会执行的 3.没有问题,那就干吧 如果try 语句里没有任何异常就会执行else中的语句 4.简洁的with语句 阅读全文
posted @ 2017-09-11 16:29 110528844 阅读(134) 评论(0) 推荐(0) 编辑
摘要: 方式一: try 检测范围 except Exception[ as reason]: 出现异常(Exception)后的处理代码 方式二:try-finally语句 try: 检测范围 except Exception[as reason]: 出现异常(Exception)后的处理代码 final 阅读全文
posted @ 2017-09-11 14:27 110528844 阅读(336) 评论(0) 推荐(0) 编辑
摘要: 逻辑错误,用户输入有误 Python标准异常总结 以下是 Python 内置异常的次构: BaseException+-- SystemExit+-- KeyboardInterrupt+-- GeneratorExit+-- Exception +-- StopIteration +-- Arit 阅读全文
posted @ 2017-09-11 12:55 110528844 阅读(176) 评论(0) 推荐(0) 编辑
摘要: 几乎可以把python的对象转换为二进制的形式存放 字节流 叫pickling 将二进制形式转换为对象的过程读取 字符流 叫unpickling >>> import pickle>>> my_list =[123,456,'I love you', ['another list']] >>> pi 阅读全文
posted @ 2017-09-11 12:27 110528844 阅读(162) 评论(0) 推荐(0) 编辑
摘要: 打开文件 help(open) open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None) Character Meaning 'r' open for 阅读全文
posted @ 2017-09-08 23:59 110528844 阅读(153) 评论(0) 推荐(0) 编辑
摘要: >>> num = {} >>> type(num) <class 'dict'> >>> num2 = {1,2,3,4,5} >>> type(num2) <class 'set'> >>> num2 {1, 2, 3, 4, 5} >>> num2[1] Traceback (most rec 阅读全文
posted @ 2017-09-08 23:49 110528844 阅读(145) 评论(0) 推荐(0) 编辑