摘要: 面向对象总结: 面向对象 概述 面向过程:关心解决问题的步骤(实现)。 算法 + 数据结构 面向对象:关心解决问题的人。 对象 + 交互 抽象:从多个事物中,舍弃个性非本质的特征, 抽离出共性与本质的过程。 类和对象 对象:大杯子 小杯子 中杯子 具体的 实例(个体) 类:杯子(数据:高度 行为:盛 阅读全文
posted @ 2019-11-24 13:29 chenlulu1122 阅读(159) 评论(0) 推荐(0)
摘要: ##魔法函数 Python内置可重写函数Python中,以双下划线开头、双下划线结尾的是系统定义的成员。我们可以在自定义类中进行重写,从而改变其行为。 __str__函数:将对象转换为字符串(对人友好的)__repr__函数:将对象转换为字符串(解释器可识别的) """ 对象 --> str 练习: 阅读全文
posted @ 2019-11-24 13:28 chenlulu1122 阅读(137) 评论(0) 推荐(0)
摘要: ##继承 多态 继承:子类完全拥有父类的数据方法多态:每个子类有自己的多元化数据方法 可以完全独立于父类,也可以在继承父类的基础上增加 Ctrl + o 继承快捷键 1.数据继承 子类没有init实例化函数,自动完全继承父类数据 class A: def __init__(self, name, a 阅读全文
posted @ 2019-11-24 13:27 chenlulu1122 阅读(110) 评论(0) 推荐(0)
摘要: #封装: 读写限制:class Garment: def __init__(self, name, price): self.name = name self.price = price @property def price(self): return self.__price @price.se 阅读全文
posted @ 2019-11-24 13:27 chenlulu1122 阅读(111) 评论(0) 推荐(0)
摘要: #高价函数 变量 = lambda 形参: 方法体 内置高阶函数 1. map(函数,可迭代对象):使用可迭代对象中的每个元素调用函数,将返回值作为新可迭代对象元素;返回值为新可迭代对象。 2. filter(函数,可迭代对象):根据条件筛选可迭代对象中的元素,返回值为新可迭代对象。 3. sort 阅读全文
posted @ 2019-11-24 11:58 chenlulu1122 阅读(105) 评论(0) 推荐(0)
摘要: #可迭代对象iterable 能够被for /对象所属类里面有 def __iter__(self)方法 for原理: for i in list1: print(i) iterable=list1.__iter__()while True: try: i=iterable.next() print 阅读全文
posted @ 2019-11-24 11:57 chenlulu1122 阅读(114) 评论(0) 推荐(0)
摘要: #时间模块import time # 1. 获取当前时间戳(从1970年1月1日到现在经过的秒数)# 1568856576.399807print(time.time()) # 2. 获取当前时间元组# tm_year=2019, tm_mon=9, tm_mday=19, tm_hour=9, t 阅读全文
posted @ 2019-11-24 11:47 chenlulu1122 阅读(102) 评论(0) 推荐(0)
摘要: #随机数模块 import random a = random.random() #随机生成0-1的小数print(a)a = random.randint(1, 2) #随机生成1-100的整数,包括100print(a)a = random.randrange(1, 2)#随机生成1-100的整 阅读全文
posted @ 2019-11-24 11:47 chenlulu1122 阅读(88) 评论(0) 推荐(0)
摘要: #模块 .py文件 导入import exercise # import 模块名 注意不加后缀.py 使用的时候用:模块名.function名 from exercise import * #使用的时间直接function名/class名 这种模式:模块中以下划线(_)开头属性不会被导入 __all 阅读全文
posted @ 2019-11-24 11:46 chenlulu1122 阅读(71) 评论(0) 推荐(0)
摘要: #异常处理 try: xxxx 可能发生错误逻辑语句except: xxx 报错后处理else: xxx 没发生错误语句finally xxx 不管有没有错都执行 -- 名称异常(NameError):变量未定义。-- 类型异常(TypeError):不同类型数据进行运算。-- 索引异常(Index 阅读全文
posted @ 2019-11-24 11:46 chenlulu1122 阅读(1087) 评论(0) 推荐(0)
摘要: #tuple创建:元组名 = (20,) #特别注意一个的时候加,元组名 = (1, 2, 3)元组名 = 100,200,300元组名 = tuple(可迭代对象) 取值:变量=元组名[index]for item in 元组名 : xxx 元组没有推导式: t=(i for i in range 阅读全文
posted @ 2019-11-24 11:45 chenlulu1122 阅读(229) 评论(0) 推荐(0)
摘要: #list 列表名.append(元素) 结尾加入元素列表.insert(索引,元素) 插入元素 列表名 = list(可迭代对象) 遍历可迭代对象加入list a=[1,2,3]b=['a','v']a+=bprint(a) [1, 2, 3, 'a', 'v']L.extend(lst) | 向 阅读全文
posted @ 2019-11-24 11:44 chenlulu1122 阅读(190) 评论(0) 推荐(0)
摘要: #dict 创建d={'name':'ch','age':21} d={}d[name]='chen' d = [(1, 2)]c = dict(d)print(c) 可迭代对象d内部元素,必须是2个元素组成 修改字典名[键] = 数据键不存在,创建记录。键存在,修改值。 取数据: 变量 = 字典名 阅读全文
posted @ 2019-11-24 11:44 chenlulu1122 阅读(114) 评论(0) 推荐(0)
摘要: #str 字符串格式化: 字符串%(变量)"我的名字是%s,年龄是%s" % (name, age) %s 字符串 %d整数 %f 浮点数 str内置函数: 判断isspace()如果字符串中只包含空白,则返回 True,否则返回 False.startswith(substr, beg=0,end 阅读全文
posted @ 2019-11-24 11:43 chenlulu1122 阅读(362) 评论(0) 推荐(0)
摘要: # cookies 和 session ##cookies记录在客户端浏览器上的数据: 比如:1.通知浏览器保存数据,下次请求内容自带这些数据发给服务器from django.http import HttpResponse def index(request): resp = HttpRespon 阅读全文
posted @ 2019-11-24 10:58 chenlulu1122 阅读(134) 评论(0) 推荐(0)
摘要: #django-admin后台管理 建立超级权限用户 python3 manage.py createsuperuser 后台管理的登录地址: - <http://127.0.0.1:8000/admin> ##自定义后台显示列表1.注册后台要显示的表 在app应用admin.py文件内 from 阅读全文
posted @ 2019-11-24 10:57 chenlulu1122 阅读(140) 评论(0) 推荐(0)
摘要: #表关系 ##一对一创建from django.db import models class Author(models.Model): name = models.CharField('姓名', max_length=50) class Wife(models.Model): name = mod 阅读全文
posted @ 2019-11-24 10:57 chenlulu1122 阅读(108) 评论(0) 推荐(0)
摘要: #聚合查询聚合:from django.db.models import * p=Book.objects.aggregate(avg_price=Avg('price')) 返回字典 p={avg_price:100} 聚合函数: - Sum, Avg, Count, Max, Min 分组聚合 阅读全文
posted @ 2019-11-24 10:56 chenlulu1122 阅读(91) 评论(0) 推荐(0)