![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Python
深夜·食堂
技能分享
展开
-
pipenv解决:WARNING: You are using pip version 20.1.1; however, version 20.2.3 is available.
解决办法:python -m pip install --upgrade pip -i https://pypi.douban.com/simple原创 2020-09-11 17:33:23 · 3042 阅读 · 0 评论 -
Python 集合处理的10个常用方法
S.add(x) 如果x不在集合S中,将x增加到SS.discard(x) 移除S中元素x,如果x不在集合S中,不报错S.remove(x) 移除S中元素x,如果x不在集合S中,产生KeyError异常S.clear() 移除S中所有元素S.pop() 随机返回S的一个元素,更新S,若S为空产生KeyError异常S.copy() 返回集合S的一个副本len(S) 返回集合...原创 2019-05-24 23:00:42 · 1233 阅读 · 0 评论 -
python 函数的定义,调用
from time import perf_counterdef fact(n): s = 1 start = perf_counter() for i in range(1,n+1): s *= i result= perf_counter()-start, s return resultresult= fact...原创 2019-05-11 18:22:56 · 168 阅读 · 0 评论 -
Python 圆周率的计算(蒙特卡罗方法)
from random import randomfrom time import perf_counterDARTS = 1000 * 1000hits = 0.0start = perf_counter()for i in range(1,DARTS+1): x, y = random() , random() dist = pow(x ** 2 + y ** 2...原创 2019-05-11 16:52:49 · 2641 阅读 · 0 评论 -
Python标准库--random--扩展随机数
基本随机数:random()seed()扩展随机数:import randomrandom.randint(0,100)0-100随机的一个整数import randomrandom.randrange(0,100,10)从0开始以步长为10不到100的,随机整数import randomrandom.getrandbits(16)生成一个11比...原创 2019-05-10 18:40:15 · 292 阅读 · 0 评论 -
Python 递归----实现字符串翻转,斐波那数列,汉诺塔
def rvs(s): if s== "": return s #递归激励 else: return rvs(s[1:])+s[0] #递归链条print(rvs("123456"))斐波那数列:def f(n): if n == 1 or n == 2 : return 1 else: ...原创 2019-05-20 18:25:02 · 539 阅读 · 0 评论 -
Python标准库--random的使用
import randomrandom.seed(10)print(random.random())print(random.random())产生两次随机数:0.5714025946899135 0.4288890546751146使用种子的作用是能够再现随机数...原创 2019-05-10 17:41:44 · 201 阅读 · 0 评论 -
Python 循环控制保留字(break,continue)
for i in "Python": if i =="y": continue print(i,end="")输出:Pthon跳出if条件成立for i in "python": if i == "t": break print(i,end="")输出:py结束循环s = "Python"while s...原创 2019-05-10 17:09:41 · 8551 阅读 · 0 评论 -
Python无限循环(while)
a = 7while a > 0: a = a-1 print(a,end=",")输出:6,5,4,3,2,1,0,原创 2019-05-10 15:21:33 · 12942 阅读 · 0 评论 -
Python 七段数码管绘制(日期)
import turtleimport timedef drawGap(): turtle.penup() turtle.fd(5)def drawLine(draw): drawGap() turtle.pendown() if draw else turtle.penup() turtle.fd(40) drawGap() tu...原创 2019-05-16 17:59:48 · 2721 阅读 · 0 评论 -
Python 序列
序列包括:字符串类型,元组类型,列表类型x in s 如果x是序列s,返回 True ,否则返回Falsex not in s 如果x是序列s,返回 False,否则返回Trues + t 链接连个序列s和ts*n 或 n*s 将序列 复制 n次s[i] 索引,返回s中的第i个元素,i是序列的序号s[i:j] 或 s[i:j:k] 切片,返回序列s中第i到j以k为步长的元素...原创 2019-05-25 18:33:18 · 277 阅读 · 0 评论 -
python开发库安装virtualenv,virtualenvwrapper
我用的是windows10系统,用的cmd命令来安装的,如果是linux用xshell就行了 ,命令都是一样的只是有稍微的差别1,打开cmd运行安装命令:pip install virtualenv2,创建testvir2虚拟环境virtualenv testvir2会在cmd当前目录下生成testvir2目录进入testvir2文件夹查看cd到test...原创 2019-06-06 18:48:06 · 123 阅读 · 0 评论 -
Python 集合操作符
S | T 返回一个新的集合,包括在集合S和T的所有元素S - T 返回一个新集合,包括在集合S但不在T中的元素S & T 返回一个新集合,包括同时在集合S和T中的元素S ^ T 返回一个新集合, 包括集合S和T中非相同元素S <= T 或 S < T 返回True/False, 判断S和T的子集关系S >= T 或 S > T 返回True/F...原创 2019-05-23 22:50:53 · 4477 阅读 · 0 评论 -
Python 集合类型
集合用大括号 {} 表示,元素间用都好分割建立集合类型用 {} 或者 set()建立空集合,必须用 set()集合里面的元素是唯一不可更改的,没有顺序A = {"PHP" , 465, ("php",45600)}其中("php",45600)为元组B = set("phppypy456")print(B)输出:{'p', 'h', '6', 'y', '4',...原创 2019-05-23 21:22:02 · 106 阅读 · 0 评论 -
Python 元组类型
元组是一种序列类型,一段创建就不能被修改使用小括号(),或者tuple()创建,元素间用逗号,分割可以使用或不使用小括号元组类型继承了序列类型的通用操作(序列操作符,序列的处理函数,序列的处理方法)def func(): return 1,2print(func(),type(func()))(1, 2) <class 'tuple'>creatu...原创 2019-05-27 22:52:42 · 733 阅读 · 0 评论 -
Python 程序打包库 pyinstaller的安装与使用
安装命令:windows:打开cmdpip install pyinstaller进入要打包程序的位置运行命令pyinstaller -F project.py会生成对应的文件夹,在dist文件里面是已经打包好的应用程序打包带图标的可执行程序图标下载:https://www.easyicon.net/命令:pyinstaller -i 1.ic...原创 2019-05-22 22:23:56 · 728 阅读 · 0 评论 -
Python (利用递归)科赫雪花的绘制
import turtledef koch(size, n): if n == 0: turtle.fd(size) else: for angle in [0, 60, -120, 60]: turtle.left(angle) koch(size/3, n-1)def main(): ...原创 2019-05-22 21:53:18 · 2594 阅读 · 0 评论 -
Python lambda函数
lambda函数是一种匿名函数,即没有名字的函数使用lambda保留字定义,函数名是返回结果lambda函数用于定义简单的,能够在一行内表示的函数lambda函数 谨慎使用,一般情况下建议使用 def 定义的函数<函数名> = lambda <参数>:<表达式>f = lambda x,y : x + yprint(f(10,20))...原创 2019-05-13 17:37:48 · 295 阅读 · 0 评论 -
Python 局部变量与全局变量
原创 2019-05-13 17:24:01 · 418 阅读 · 0 评论 -
Python循环(for)
for i in range(7): print(i,end="")输出:0123456for i in range(1,8,2): print(i,end="")输出:1357num = ['P','y','t','h','o','n']for i in num: print(i,end="-")输出:P-y-t-h-o-...原创 2019-05-10 15:15:53 · 669 阅读 · 0 评论 -
Python 文本进度条
scale = 10print("{:-^20}".format("执行开始"))for i in range(scale+1): a = "*" * i b = "." * (scale-1) c = (i/scale)*100 print("{:^3.0f}%{}->{}".format(c,a,b)) time.sleep(0.1)pri...原创 2019-05-07 16:30:46 · 1045 阅读 · 0 评论 -
Python 程序计时
原创 2019-05-07 16:09:35 · 534 阅读 · 0 评论 -
Python turtle库的画笔控制
turtle.penup() 别名 turtle.pu() :抬起画笔海龟在飞行turtle.pendown() 别名 turtle.pd():画笔落下,海龟在爬行turtle.pensize(width) 别名 turtle.width(width) :设置画笔的宽度,海龟的腰围turtle.pencolor(color) color为颜色字符串或r,g,b值 ...原创 2019-04-24 16:38:19 · 10193 阅读 · 0 评论 -
Python字符串处理函数
Str = "AasdfgASedfgDGSGSDTEWZ"print(Str.lower()) #将支字符串转换成小写#aasdfgasedfgdgsgsdtewzprint(Str.upper()) #将支字符串转换成大写#AASDFGASEDFGDGSGSDTEWZCtr = "A,b,C"print(Ctr.split(",")) #返回一个列表,由Ctr根据 ...原创 2019-04-28 22:31:38 · 133 阅读 · 0 评论 -
Python 字符串切边的的高级用法(根据步长对字符串切片,将字符串进行逆序排列)
numStr = "0一二三四五六七八九十"print(numStr[0:9:2],end="")# 0二四六八print("")#换行print(numStr[::-1],end="")# 十九八七六五四三二一0原创 2019-04-28 17:36:55 · 1341 阅读 · 0 评论 -
Python实现简单温度转换(华氏温度)
# @Author : 望天宇八方清似玉# @CreateTime: 2019/4/22 17:50# @File : Temp.py# @Software : PyCharmTempStr = input("请输入带有符号的温度值: ")if TempStr[-1] in ['F', 'f']: C =(eval(TempStr[0:-1])-32)/1.8...原创 2019-04-22 18:07:31 · 13167 阅读 · 5 评论 -
Python语句与函数 输入函数 分支语句 打印函数 评估函数
评估函数 eval:去掉参数最外侧引号并执行余下语句的函数eval("1")1eval("1+2")3eval('print("疯子愿望")')'疯子愿'TempStr = "12.46"eval(TempStr[0:-1])12.4...原创 2019-04-22 17:34:35 · 202 阅读 · 0 评论 -
Python数据类型
列表类型:由0个或多个数据组成的有序序列列表使用 [ ] 表示,采用逗号 (,) 分割各元素['Y','y']表示两个元素 'Y' 和 'y'使用保留字 in 判断一个元素是否在列表中TempStr = 'wangtianyubafangqingshiyu'TempStr[-1] in ['Y','y'] 返回bool值...原创 2019-04-22 17:05:13 · 94 阅读 · 0 评论 -
Python字符串的使用:索引,切片
[1:3] :取出第一个字符和第二个字符但不到第3个字符,TempStr[0:-1]:取出最后一个字符s = "12345678"print(s[:0:-1])输出:8765432print(s[1:-1])输出:234567print("12345678"[::-1])输出:87654321print("12345678"[1:8:2])输出:24...原创 2019-04-22 16:55:07 · 571 阅读 · 0 评论 -
Python range()
for item in range(5) print(item)01234for item in range(2,5) print(item,end="")2 3 4原创 2019-04-24 17:31:45 · 915 阅读 · 0 评论 -
Python 时间格式化
t = time.gmtime()print(time.strftime("%Y-%m-%d %H:%M:%S",t))# 2019-05-07 07:54:35原创 2019-05-07 16:02:19 · 759 阅读 · 0 评论 -
Python time()库
import timeprint(time.time())print(time.ctime())# 7215127.4737623# Tue May 7 15:45:27 2019print(time.gmtime())# time.struct_time(tm_year=2019, tm_mon=5, tm_mday=7, tm_hour=7, tm_min=47, tm_s...原创 2019-05-07 15:50:07 · 108 阅读 · 0 评论 -
Python实现简单身体质量指数BMI(对身体质量的刻画)
height, weight = eval(input("请输入身高(米)和体重\(公斤)[逗号割开]:"))bim = weight / pow(height,2)print("BIM值为{:.2f}".format(bim))who, nat= "",""if bim < 18.5: who,nat = "偏瘦","偏瘦"elif 18.5 <= bim <...原创 2019-05-09 18:33:29 · 5515 阅读 · 1 评论 -
Python异常处理
try: num = eval(input("请输入一个整数:")) print(num**2)except: print("输入错误") try: num = eval(input("请输入一个整数:")) print(num**2)except: print("输入的不是整数")else: print("输入正...原创 2019-05-09 17:41:35 · 206 阅读 · 0 评论 -
Python 分支结构
原创 2019-05-09 17:09:40 · 119 阅读 · 0 评论 -
视觉跟踪算法库 PySOT
https://pypi.org/project/pySOT/https://github.com/STVIR/pysot原创 2019-05-14 09:09:16 · 2906 阅读 · 2 评论 -
Python字符串类型的格式化——(.format())
# 字符串类型格式化formats = "姓名:{},年龄:{},性别:{}".format("马云","16","男")print(formats)# 姓名:马云,年龄:16,性别:男formats = "姓名:{2},年龄:{1},性别:{0}".format("马云","16","男")#曹中的数字代表format的中的第几个参数print(formats)# 姓名:男,年龄...原创 2019-05-07 15:36:27 · 886 阅读 · 1 评论 -
Python 数字;类型及操作
原创 2019-04-25 15:55:48 · 131 阅读 · 0 评论 -
Python关键字(保留字)
原创 2019-04-22 16:41:24 · 13825 阅读 · 0 评论