
Python
蚂蚁蚂蚁大蚂蚁
不会写代码的测试不是好厨子
展开
-
Python-time
import time# 返回当前时间的时间戳(从1970年1月1日00时00分00秒到现在的浮点秒数)print(time.time()) # 1590326750.3151598# ime.localtime( )函数的作用是格式化时间戳为本地时间(struct_time类型)。# 如果secs参数未传入,就以当前时间为转换标准print(time.localtime()) # time.struct_time(tm_year=2020, tm_mon=5, tm_mday=24, tm_ho原创 2020-05-24 21:36:34 · 262 阅读 · 1 评论 -
Python——remove
a = [1,2,3,4,5,6]for i in a: print(i) print(a) a.remove(i) print(a) """ 1 [1, 2, 3, 4, 5, 6] [2, 3, 4, 5, 6] 3 [2, 3, 4, 5, 6] [2, 4, 5, 6] 5 [2, 4, 5, 6] [2, 4, 6] """第一次执行时,i纸箱第一个元素,即1,remove将1删除,进行第二次循环,此时i指向第二个元素,因此为3。原创 2020-05-20 22:36:38 · 255 阅读 · 0 评论 -
python3——乘除的运算符
1、python2的除法自动取整,Python3则显示小数部分a = 2b = 3c = a * bprint("a * b:",c)d = a ** bprint("a ** b:", d)a = 5b = 23e = b/aprint("a/b:", e)f = b//aprint("a//b:", f)g = b%aprint(" b%a:", g)"""a * b: 6a ** b: 8a/b: 4.6a//b: 4b%a: 3"""2、自动向上取整原创 2020-05-10 15:24:57 · 1502 阅读 · 0 评论 -
(转载)Python中进制转换函数的使用
https://www.cnblogs.com/ZN-225/p/11291545.html转载 2020-05-07 23:00:42 · 283 阅读 · 0 评论 -
Python3——输入指定进制的数据
try: # 将输入的数字转换为十进制 print(int(input(), 2)) print(int(input(), 8)) print(int(input(), 16)) ''' 10(输入) 2 10(输入) 8 10(输入) 16 '''except BaseException as e:...原创 2020-05-07 22:56:58 · 286 阅读 · 0 评论 -
Python3——字符串操作(仅去空格、深复制、浅复制、连接、查找、切片)
字符串常用操作import copy# 去掉空格string = " python "both = string.strip()print(both)left = string.lstrip()print(left)right1 = string.rstrip()print(right1)# 复制字符串a = "python"b = ac = copy.copy(a...原创 2020-05-07 22:50:38 · 774 阅读 · 0 评论 -
Python——操作mysql数据库
Python3和Python2操作mysql数据库用的三方库分别是pymysql和mysqldb。二者用法相同。本文以Python3为例。1、批量插入以及查询数据import pymysqlimport uuiddb = pymysql.connect("192.168.1.143","root","123456","pytest")cur = db.cursor()print(typ...原创 2020-05-05 21:09:44 · 260 阅读 · 0 评论 -
转载——python关键参数、位置参数以及默认参数
python的位置参数、默认参数、关键字参数、可变参数区别原文地址:https://www.cnblogs.com/bingabcd/p/6671368.html一、位置参数调用函数时根据函数定义的参数位置来传递参数。复制代码#!/usr/bin/env pythoncoding=utf-8def print_hello(name, sex):sex_dict = {1: u’先生...转载 2020-04-15 23:21:17 · 467 阅读 · 0 评论 -
Python——pytest之fixture的作用范围
import pytestclass Test_fix(): @pytest.fixture() def user(self): print("用户名") a = "admin" return a @pytest.fixture() def psw(self): print("密码") ...原创 2020-04-08 23:40:34 · 539 阅读 · 0 评论 -
python__读写Excel文件
Python操作Excel文件,主要通过两个库,一个是xlrd,用来读取文件,另一个是xlwt,用来写入。在开始之前,先展示一个Excel的内容,我操作的Excel表格内容如下:一个Excel文件中,共两张表格,第一张名字叫做IP,第二组名字叫做person,后面将对这个Excel文件进行读写操作一、读1、# 打开文件,读取文件数据workbook = xlrd.open_workb...原创 2020-03-22 21:49:08 · 158 阅读 · 0 评论 -
Python3 正则表达式(1)——match&&seach的区别
1、首先看match和search的区别,每个print对应的输出在注释中标明。import re'''在Python的string前面加上‘r’, 是为了告诉编译器这个string是个raw string,不要转意backslash "\" 。 "\n" 在raw string中,是两个字符,"\"和"n",而不会转意为换行符。由于正则表达式和"\"会有冲突,因此,当一个字符串使用了正则...原创 2020-01-31 12:19:49 · 478 阅读 · 0 评论 -
Python3—写入csv文件
import jsonimport codecsres = { "system": "success", "code": 200, "message": "中文"}res = json.dumps(res, ensure_ascii=False)res = str(res)f = codecs.open("./read.csv","a",encoding="gb...原创 2020-01-25 17:40:38 · 317 阅读 · 0 评论