要一直走下去

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

随笔分类 -  Python

摘要:一、基本的例子 ''' 概念:类、对象、 封装(防止数据被随意修改,外部调用变得简单)、 继承(共同点在父类,不同点在子类)、 多态(子类重写父类方法,对不同类的对象发出相同的消息将会有不同的行为) ''' class Dog: nation = "JAPAN" def __init__(self, 阅读全文
posted @ 2018-07-23 21:41 要一直走下去 阅读(263) 评论(0) 推荐(0)

摘要:object的方法 比较的特殊方法: 特殊方法 使用 描述 __lt__(self.other) x<y 如果x<y,则返回true __le__(self.other) x<=y 如果x<=y,返回true __eq__(self.other) x==y 如果x==y,返回true __ne__( 阅读全文
posted @ 2018-07-18 00:22 要一直走下去 阅读(147) 评论(0) 推荐(0)

摘要:Lambda函数可以具有任意数量的参数,但只能有一个表达式。该表达式将被求值并返回 f = lambda x, y: x ** y # 返回x的y次方 f1 = lambda x: x + 1 # 返回x+ 我们通常使用Lambda函数作为高阶函数的参数,该函数以其他函数作为参数。匿名函数与内置函数 阅读全文
posted @ 2018-07-06 09:54 要一直走下去 阅读(349) 评论(0) 推荐(0)

摘要:一、整型(int) # int对象初始化 x = 2 y = int(3) n = int("A3",12) # 运算符(+、-、*、/、//、%、**) ''' 相关的函数 ''' abs(x) #求绝对值 divmod(x,y) #求x/y的商和余数,返回元祖 pow(x,y) #求x的y次方 阅读全文
posted @ 2018-07-06 09:40 要一直走下去 阅读(251) 评论(0) 推荐(0)

摘要:列表: L.append(x) # x追加到L尾部 L.count(x) # 返回x在L中出现的次数 L.extend(m) # Iterable m的项追加到L末尾 L += m # 功能同L.extend(m) L.index(x, start, end) # 返回x在列表L(或者L[start 阅读全文
posted @ 2018-07-06 09:40 要一直走下去 阅读(287) 评论(0) 推荐(0)

摘要:''' logging模块: logging的日志可以分为 debug():Detailed information, typically of interest only when diagnosing problems. info():Confirmation that things are w 阅读全文
posted @ 2018-07-06 09:39 要一直走下去 阅读(247) 评论(0) 推荐(0)

摘要:抛出异常写法: raise KeyError(obj) # obj可以为字符串,数字,元祖,列表,字典等任意类型。 ''' 异常处理格式 ''' try: pass except KeyError as e: print("key error..", e) except IndexError as 阅读全文
posted @ 2018-07-06 09:39 要一直走下去 阅读(155) 评论(0) 推荐(0)

摘要:Random模块: #!/usr/bin/env python #_*_encoding: utf-8_*_ import random print (random.random()) #0.6445010863311293 #random.random()用于生成一个0到1的随机符点数: 0 <= 阅读全文
posted @ 2018-07-06 09:36 要一直走下去 阅读(253) 评论(0) 推荐(0)

摘要:i+1: 当前的数量 300: 总数量 import sys print("下载中...") def process(curr, count): cursor_count = curr // int(count * 0.02) str = '>' * cursor_count + ' ' * (50 阅读全文
posted @ 2018-07-06 09:36 要一直走下去 阅读(107) 评论(0) 推荐(0)

摘要:散装知识点1:Python简介解释型语言:解释,执行,解释,执行...编译型语言:编译,连接,执行解释型语言:解释器编译型语言:编译器,解释型语言:解释源码,不同平台使用不同的解释器就行编译型语言:不同平台编译成不同的机器码python2.4最普及的版本Python2.6、2.7是过渡版本Pytho 阅读全文
posted @ 2018-07-06 09:24 要一直走下去 阅读(240) 评论(0) 推荐(0)

摘要:1、高阶函数(函数即变量) ''' 一个函数add()接收另一个函数abs作为参数,add称为高阶函数 ''' def add(a, b, f): return f(a) + f(b) res = add(-1,-3,abs) print(res) 2、嵌套函数-->闭包 def outer(): 阅读全文
posted @ 2018-07-06 09:24 要一直走下去 阅读(131) 评论(0) 推荐(0)