首页 文章 精选 留言 我的

精选列表

搜索[Python],共10000篇文章
优秀的个人博客,低调大师

分享某行软件开发中心的两道python笔试题

两道笔试题都是选择题,两个知识点,容易做错。 第一题 ## 下面程序执行结果 x = 2 def b(a): x = x+a b(3) print(x) 此段程序运行报错,UnboundLocalError: local variable 'x' referenced before assignment 应采用global关键字定义全局变量 x = 2 def b(a): global x x = x+a b(3) print(x) 第二题 a = [x for x in range(3)] import numpy as np a = np.array(a) a**a [1,1,4] 0**0 = 1,容易犯迷糊。

优秀的个人博客,低调大师

Python全栈 MySQL 数据库 (表字段增、删、改、查、函数)

ParisGabriel 每天坚持手写一天一篇 决定坚持几年 为了梦想为了信仰 开局一张图 查询SQL变量show variables 1.表字段的操作 1.语法:alter table表名 执行动作; 2.添加字段(add) alter table表名add字段名 数据类型;(尾插) alter table 表名 add 字段名 数据类型first;(头插) alter table 表名 add 字段名 数据类型after字段名;(指定插入) 3.删除字段(drop) alter table 表名drop字段名; 4.修改数据类型(modify) alter table 表名modify字段名 新数据类型; 5.重命名(rename) alter table 表名rename表名;2.字符类型 1.字符类型宽度与数值类型宽度的区别 1.数值类型宽度为显示宽度,只用于select查询显示 占用储存无关,可用zerofill查看效果 2.枚举类型 1.单选(enum):字段名enum(值1,值2...); 2.多选(set):字段名set(值1,值2...); (多项放在一个字符串内用,号隔开) 3.日期时间类型 1.date:“YYYY-MM-DD” 2.time:“HH:MM:SS” 3.datetime:“YYYY-MM-DD HH:MM:SS” 4.timestamp:“YYYY-MM-DD HH:MM:SS” 5.datetime:不给值默认返回Null 6.timestamp:不给值默认返回系统时间 3. 日期时间函数 1.now()返回服务器当前的时间 2.curdate()返回当前时期 3.curtime()返回当前日期 4.year(date)返回指定时间的年份 5.date(date)返回指定时间的日期 6.time(date)返回指定时间的时间4.日期时间运算 1.语法格式 select * from 表名 where 字段名 运算符(时间-interval时间间隔单位); 时间间隔单位: 1 day | 2hour | 1 minute | 2year | month 5.表记录管理 1.删除表记录 1.deletefrom 表名 where 条件; 注意: 如果不加where条件,所有记录全部清空 2.更改表记录 1.update表名 set 字段1=值1,字段名2=值2,... where 条件 注意: 如果不加where条件,所有记录全部更改 3.运算符操作 1.数值比较/字符比较 1.数值比较: = != > >= < <= 2.字符比较: = != 2.逻辑比较 1.and 2.or 3.范围内比较 1.where 字段名between值1 and 值2 2.where 字段名in(值1,值2,....) 3.where 字段名not in(值1,值2,...) 4.匹配空、非空 1.空:where nameisnull 2.非空:where nameis notnull 3.注意 1.NILL:空值,只能用is或is not取匹配 2.“ ”:空字符串,用=或!=去匹配 4.模糊比较 1.where 字段名like表达式 2.表达式 1._:匹配单个字符 2.% :匹配0到多个字符 NULL不会被统计6.SQL查询: 1语法顺序: 3.select... 聚合函数from表名 1.where 2.group by... 4.having... 5.order by... 6.limit...; 2.order by 1.给出查询结果进行排序 2...order by字段名 升序/降序 升序:ASC(默认排序方式) 降序:DESC 3.limit(永远放在SQL语句的最后) 1.作用:显示查询记录的个数 2.用法 limitn 显示n条记录 limit m,n m表示 从m+1条记录开始显示显示n条记录 limit 2,3 显示第3,4,5条记录 3.分页 每页显示5条记录,显示第4页内容 第1页:limit 0,5 #1,2,3,4,5 第2页:limit 5,5 第3页:limit 10,5 第4页:limit 15,5 每页显示n条记录,显示第m页: limit(m-1)*n,n4.聚合函数 avg(字段名):求该字段的平均值 sum(字段名):求和 max(字段名):最大值 min(字段名):最小值 count(字段名):统计该字段的个数 create database MOSHOU; use MOSHOU; create table hero( id int, name char(15), sex enum("男","女"), country char(10) )default charset=utf8; insert into hero values (1,"曹操","男","魏国"), (2,"小乔","女","吴国"), (3,"诸葛亮","男","蜀国"), (4,"貂蝉","女","东汉"), (5,"赵子龙","男","蜀国"), (6,"魏延","男","蜀国"); use MOSHOU; create table sanguo( id int, name char(20), gongji int, fangyu tinyint unsigned, sex enum("男","女"), country varchar(20) )default charset=utf8; insert into sanguo values (1,'诸葛亮',120,20,'男','蜀国'), (2,'司马懿',119,25,'男','魏国'), (3,'关羽',188,60,'男','蜀国'), (4,'赵云',200,66,'男','魏国'), (5,'孙权',110,20,'男','吴国'), (6,'貂蝉',666,10,'女','魏国'), (7,null,1000,99,'男','蜀国'), (8,'',1005,88,'女','蜀国'); 1、创建库 studb2 2、在库中创建表 t1 ,字段有3个:name、age、phnumber 3、查看表结构 4、在表中第一列添加一个 id 字段 5、把 phnumber 的数据类型改为 bigint 6、在表中最后一列添加一个字段 address 7、删除表中的 age 字段 8、查看表结构 答案: use studb2; create table t1( name char(20), age tinyint unsigned, phnumber char(11) ); desc t1; alter table t1 add id int first; alter table t1 modify phnumber bigint; alter table t1 add address varchar(50); alter table t1 drop age; desc t1; 1、在表中插入3条记录 2、查找2018年7月2日有哪些用户充值了 3、查找2018年7月份充值的信息 4、查找7月30日10:00-12:00充值的信息 答案: insert into t7 values (3,"小昭",19000520,3000,20180630000000), (4,"赵敏",19000521,4000,20180702000000), (5,"周芷若",19010522,3500,20180702100000); select * from t7 where date(shijian)="2018-07-02"; select * from t7 where date(shijian)>="2018-07-01" and date(shijian)<="2018-07-31"; select * from t7 where date(shijian)="2018-07-31" and time(shijian)>="10:00:00" and time(shijian)<="12:00:00"; 1、查询1天以内的记录 2、查询1年以前的记录 3、查询1天以前,3天以内的记录 答案: select * from t7 where shijian > (now()-interval 1 day); select * from t7 where shijian < (now()-interval 1 year); select * from t7 where shijian < (now()-interval 1 day) and shijian > (now()-interval 3 day); 1、查找所有蜀国人的信息 2、查找所有女英雄的姓名、性别和国家 3、把id为2的记录改为典韦,性别男,国家魏国 4、删除所有蜀国英雄 5、把貂蝉的国籍改为魏国 6、删除所有表记录 答案: select * from hero where country="蜀国"; select name,sex,country from hero where sex="女"; update hero set name="典韦",sex="男",country="魏国" where id=2; delete from hero where country="蜀国"; update hero set country="魏国" where name="貂蝉"; delete from hero; 1、找出攻击值高于200的蜀国英雄的名字、攻击力 2、将吴国英雄中攻击值为110的英雄的攻击值改为100,防御力改为60 3、查找蜀国和魏国的英雄信息 答案: select name as n,gongji as g from sanguo where gongji>200 and country="蜀国"; update sanguo set gongji=100,fangyu=60 where country="吴国" and gongji=110; select * from sanguo where country="蜀国" or country="魏国"; 1、查找攻击值100-200的蜀国英雄信息 2、找到蜀国和吴国以外的国家的女英雄信息 3、找到id为1、3或5的蜀国英雄 和 貂蝉的信息 答案: select * from sanguo where gongji between 100 and 200 and country="蜀国"; select * from sanguo where country not in("蜀国","吴国") and sex="女"; select * from sanguo where (id in(1,3,5) and country="蜀国") or name="貂蝉"; 1、在蜀国英雄中,查找防御值倒数第二名至倒数第四名的英雄的记录 2、在蜀国英雄中,查找攻击值前3名且名字不为 NULL 的英雄的姓名、攻击值和国家 答案: select * from sanguo where country="蜀国" order by fangyu asc limit 1,3; select name,gongji,country from sanguo where country="蜀国" and name is not NULL order by gongji DESC limit 3; 1、攻击力最强值是多少 2、统计id 、name 两个字段分别有几条记录 ## 空值 NULL 不会被统计,""会被统计 3、计算蜀国英雄的总攻击力 4、统计蜀国英雄中攻击值大于200的英雄的数量 答案: select max(gongji) from MOSHOU.sanguo; select count(id),count(name) from sanguo; select sum(gongji) from MOSHOU.sanguo where country="蜀国"; select count(*) from MOSHOU.sanguo where gongji>200 and country="蜀国";

优秀的个人博客,低调大师

给妹子讲python-S01E03元组的使用

【妹子说】今天这一集,我们来学学容器这一部分的最后一块内容,元组吧~ 元组很简单,核心就是一句话:可以看作是不可变的列表 T = (1,2,3,4) M = ('spam', 3.0, [11,22,33]) print(T[1]) print(M[2][0]) 2 11 元组有一种特殊的方法,可以一次性获取元组中的所有项 a,b = (1,2) print('a={},b={}'.format(a,b)) a=1,b=2 他也可以和其他元组进行连接操作 T1 = (1,2,3,4) T2 = (5,6,7,8) print(T1 + T2) (1, 2, 3, 4, 5, 6, 7, 8) 基于位置偏移的操作如索引和分片,元组和列表的用法完全一样。他和列表的关键区别在于他的不可变性,这有利于保持数据的完整性。 至于说元组的排序,由于

优秀的个人博客,低调大师

python+pytest单元测试框架之生成各种格式测试报告

前面讲到使用pytest执行单个、多个或指定的测试用例。接下来讲解下通过运行测试用例,怎么来生成不同格式的测试报告 首先,创建test_calss.py 测试用例文件,这里以测试该文件为例 #coding:utf-8 class TestClass(): def test_one(self): x = "this" assert "h" in x def test_two(self): x = "hello" assert x == "hi" def test_three(self): x = "world" assert x != "worl" 一、生成ResultLog文件 1.在CMD中切换到该测试用例路径下,执行指令:py.test test_class.py --resultlog=./log.txt (其中./log.txt为生成log的路径,也可写成py.test test_class.py --resultlog=E:/log.txt)。并早当前路径下生成log.txt文件,打开文件,内容如下 执行结果1 二、生成JunitXML文件 1.在CMD中切换到该测试用例路径下,执行指令:py.test test_class.py --junitxml=./log.xml (其中./log.xml为生成log的路径,也可写成py.test test_class.py --junitxml=E:/log.xml)。并在当前路径下生成log.xml文件,打开文件,内容如下 执行结果2 三、创建测试用例的URL 1.在CMD中切换到该测试用例路径下,执行指令:py.test test_class.py --pastehbin=all 会在最后一行生成一个网址 执行结果3-1 2.把网址(https://bpaste.net/show/5e60a2096e54)复制到浏览器打开可以看到测试用例执行的全部结果 执行结果3-2 3.指定显示测试结果为FAIL,输入指令:py.test test_class.py --pastebin=failed 执行结果3-3 四、生成HTML测试报告 1.要想生成html格式的测试报告,首先的下载安装pytest-html插件,执行如下指令:pip install pytest-html 如下图 安装pytest-html插件 2.在CMD中切换到该测试用例路径下,执行指令:py.test test_class.py --html=./report.html (其中./report.html为生成log的路径,也可写成py.test test_class.py --html=E:/report.html)。并在当前路径下生成report.html文件,打开文件,内容如下 执行结果4-1 3.双击打开生成的report.html文档,可以看到如下效果 执行结果4-2 其中,红色框框内的选项可以自行选择是否显示。

优秀的个人博客,低调大师

python类继承,父类和子类的构造函数初始化调用

# class Info(object): # def __init__(self,name,age,score): # self.Name = name # self.Age = age # self.Score = score # # # class Student(object): # def __init__(self,info): # self.Info = info # # # Home = "地球" # # __Sxt = "女" # # # # def GetSex(self): # # return Student.__Sxt # # # # def __init__(self,name,age,score,comp): # # self.Name = name # # self.Age = age # # self.Score = score # # self.__Comp = comp # # # # def GetComp(self): # # return self.__Comp # # # # def SetComp(self,comp): # # self.__Comp = comp # # # stu = Student("gou",21,98) # # # # stu.Home = "火星" # # print(stu.Home) # # print(stu.__class__.Home) # # print(Student.Home) # # # stu1 = Student("a",11,33,"mac") # # print(stu1.GetComp()) # # stu1.SetComp("deal") # # print(stu1.GetComp()) # # # # print(stu1.GetSex()) # # # info = Info("a",18,98) # stu = Student(Info("a",18,98)) # # print(type(stu)) # print(type(stu.Info)) # print(stu.Info.Name) # 信息基类 class MemberInfo(object): __name = None __age = None __score = None def __init__(self,name,age,score): print("parent init") self.__name = name self.__age = age self.__score = score def GetName(self): return self.__name class Student(MemberInfo): def __init__(self,name,age,score,comp): MemberInfo.__init__(self,name,age,score) print("child init") self.__Comp = comp def GetComp(self): return self.__Comp # # # stu = Student("a",15,98) # stu = Student("mac") # print(stu.GetComp()) stu = Student("gou",18,98,"mac") print(stu.GetName()) print(stu.GetComp())

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册