首页
关于
留言
友情链接
推荐
粽子SHOP
Search
1
粽子SHOP即时到账 微信插件(MyWechat)
5,938 阅读
2
Windows Navicat Premium16.3.2 免安装 绿色汉化版
5,603 阅读
3
PS人像美颜插件 DR5.0增强版 一键人像磨皮/美白/高低频
5,194 阅读
4
彩虹聚合登录API源码/上元二开 QQ互联分发
4,172 阅读
5
电脑同时外放两个蓝牙音响,实现全屋立体声效果(Virtual Audio Cable)
3,353 阅读
程序源码
PHP源码
HTML源码
精品程序
易语言源码
Python源码
活动资讯
技术分享
实用代码
实用工具
学习笔记
PHP笔记
前端笔记
uniapp
Python
逆向
docker
Dify
thinkPHP
登录
Search
标签搜索
python
docker
typescript
swoole
thinkphp6
php
R语言
dify
composer
composer命令
tp6
tp中间件
vue
node.js
粽子shop
thinkSwoole
微信监控
AI
timi
王者荣耀
烂掉的ay
累计撰写
114
篇文章
累计收到
1,322
条评论
首页
栏目
程序源码
PHP源码
HTML源码
精品程序
易语言源码
Python源码
活动资讯
技术分享
实用代码
实用工具
学习笔记
PHP笔记
前端笔记
uniapp
Python
逆向
docker
Dify
thinkPHP
页面
关于
留言
友情链接
推荐
粽子SHOP
搜索到
24
篇与
Python
的结果
2023-04-02
Python 函数定义 模块与包的使用
在python中,每个py可以看作是一个模块,可以使用import导入使用其中的变量或函数函数定义在 demo2.py 中定义函数 # 函数 # def funName(): 定义函数 def echoString(str): ''' 这是函数的注释 :param str: :return: ''' print(str) #echoString("hello world") def nums(num1,num2): ''' 数字相加 :param num1: :param num2: :return: ''' num3 = num1 + num2 print(" %d + %d = %d" % (num1,num2,num3)) #nums(2,3) # 带返回值的函数 def nums2(num1,num2): return num1+num2 num3 = nums2(5,6) # >>> 11 #print(num3) 在 demo3.py 中引入 demo2.py 并使用import demo2 demo2.echoString("在demo3中调用demo2的方法") print(demo2.num3) {dotted startColor="#ff6c6c" endColor="#1989fa"/}模块与包使用PyCharm右键,新建python软件包会自动创建 __init__.py 文件在包下创建两个文件 receive.py 与 send.py 分别入两个函数def msg(str): print("接收信息:%s" % str)def msg(str): print("发送信息:%s" % str)在__init__.py 文件中写入代码from . import send from . import receive创建 test.py 导入包并使用import test_ test_.send.msg("你好") test_.receive.msg("hello")
2023年04月02日
385 阅读
0 评论
0 点赞
2023-04-02
Python pip更新、国内镜像源、常用包安装
pip更新pip install --upgrade pip{dotted startColor="#ff6c6c" endColor="#1989fa"/}常用的pip国内镜像源:清华大学:https://pypi.tuna.tsinghua.edu.cn/simple/阿里云:http://mirrors.aliyun.com/pypi/simple/中国科技大学:https://pypi.mirrors.ustc.edu.cn/simple/豆瓣:http://pypi.douban.com/simple/你可以在使用pip安装Python包时,通过添加-i参数指定使用其中一个镜像源,例如:pip install 包名 -i 镜像源地址{dotted startColor="#ff6c6c" endColor="#1989fa"/}例如 使用清华大学的镜像源安装常用的包numpy包:pip install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple/opencvpip install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple/wxpythonpip install wxpython -i https://pypi.tuna.tsinghua.edu.cn/simple/pywin32pip install pywin32 -i https://pypi.tuna.tsinghua.edu.cn/simple/Djangopip install Django -i https://pypi.tuna.tsinghua.edu.cn/simple/execjspip install PyExecJS -i https://pypi.tuna.tsinghua.edu.cn/simple/{dotted startColor="#ff6c6c" endColor="#1989fa"/}
2023年04月02日
409 阅读
0 评论
0 点赞
2023-04-01
Python 循环、列表、字典、集合的定义和常用方法
学习干货循环 i = 1 # 声明变量 while i <= 5: print("while,Hello World") i += 1 else: # 也可以不用else print("while 循环结束后 i= %d" % i ) print(" ---------------------------- " ) for k in range(5): print("for,hello") print("for 循环结束后 k= %d" % k ) print(" ---------------------------- " ) a = 1 while a <= 5: if( a == 3): print("if, a = 3") break else: print( "else, a = %d" %a) a += 1 else: # 如果break了,不会执行else print("while 正常结束" ) print("while 循环结束后 a= %d" % a ) 列表 name_list = [ "张三","李四","王五"] print(name_list) # 直接修改数据 name_list[1] = "王一博" print(name_list) # 在指定未知插入数据 】 # insert(下标,元素) 插入数据 # append(元素) 追加数据 name_list.insert(0,"小唐插队") print(name_list) name_list.insert(2,"小曾插队") print(name_list) name_list.append("小周跟队") print(name_list) # del 删除指定数据 del name_list[2] print(name_list) name_list.append("小周跟队") print(name_list) # remove 删除第一次出现的元素 name_list.remove("小周跟队") print(name_list) # pop 删除 name_list.pop() # 删除最后一个数据 print(name_list) name_list.pop(0) # 删除指定数据 print(name_list) # clear 清空数据 # name_list.clear() # print(name_list) name_list.append("小页跟队") name_list.append("小页跟队") print(name_list) # len 列表长度 print( "列表长度 = %d" % len(name_list) ) # count 统计元素出现的次数 print( "小页跟队 出现次数 = %d" % name_list.count("小页跟队") ) # sort 列表排序 number_list = [ 2,1,4,3,7,5] print(number_list) # sort() 升序 number_list.sort() print(number_list) # sort(reverse=True) 降序 number_list.sort(reverse=True) print(number_list) # reverse 逆序 (列表当前排序反过来) number_list.reverse() print(number_list) # extend 将两个列表合并 test_1 = [ 10,11,12 ] test_2 = [ 13,14,15 ] test_1.extend(test_2) print(test_1) 元组 # ````````````````````````` # 元组 # 和列表类似,不同之处是 元组的 元素不能修改 # 表示多个元素组成的序列 # 在python开发中 有特定的应用场景 # 元组用()定义 info_tuple = ("张三",18,1.75) 。 只有一个数据时,需要在后面添加逗号 info_tuple = ("李四",) # 索引从0开始 # ````````````````````````` info_tuple = ("张三",18,1.75,18) print(info_tuple) print( type(info_tuple) ) # count 统计元素出现的次数 print( "18出现的次数 = %d" %info_tuple.count(18)) # index 元素出现的下表 print( info_tuple.index(1.75)) print( " 元组的循环 :") for i in info_tuple: print(i) # list 转list类型 print( list(info_tuple)) # tuple 转tuple类型 print( tuple(info_tuple)) 字典# ````````````````````````` # 字典 # 通常用于存储 描述一个物体的相关数据 # 字典是无序的对象集合 ,列表是有序的对象集合 # 字典用{}定义 ,键值对方式 zhangsan = { "name" :"张三","age":18} # ````````````````````````` zhangsan = { "name" :"张三","age":18} print(zhangsan) print( type(zhangsan)) zhangsan['height'] = 1.75 print(zhangsan) # setdefault 有则不修改,没有则新增 zhangsan.setdefault("height",1.80) zhangsan.setdefault("address","中国") zhangsan.setdefault("gender",True) print(zhangsan) print( zhangsan.get("name") ) print( zhangsan.keys() ) print( zhangsan.values() ) print( zhangsan.items() ) # del 删除 del zhangsan['address'] print( zhangsan ) # 打印要删除的值 print( zhangsan.pop("age")) print( zhangsan ) # 随机删除 print( zhangsan.popitem()) print( zhangsan ) zhangsan['name'] = "三哥" print( zhangsan ) # update 合并字典 zhangsan_data = { "m" :"李四","f":"张无忌"} zhangsan.update(zhangsan_data) print( zhangsan ) print("------------------") # 字典循环 for k,v in zhangsan.items(): print(k,v) print("------------------") # 字典循环 for k in zhangsan: print("%s : %s" % (k,zhangsan[k])) 集合# ````````````````````````` # 集合 # 无序、互异、确定 # ````````````````````````` set1 = {1,2,2,3,4,10} print(set1) # >>> {1, 2, 3, 4,10} set2 = set('hello') print(set2) # >>> {'l', 'h', 'e', 'o'} set3 = { num for num in range(1,20) if num % 3 == 0 or num % 5 == 0} print(set3) # >>> {3, 5, 6, 9, 10, 12, 15, 18} # in 元素是否在集合中 print(10 in set3) # >>> True print(10 not in set3) # >>> False # & 交集 print( set1 & set3) # >>> {10, 3} print( set1.intersection(set3)) # >>> {10, 3} # 并集 print( set1 | set3) # >>> {1, 2, 3, 4, 5, 6, 9, 10, 12, 15, 18} print( set1.union(set3)) # >>> {1, 2, 3, 4, 5, 6, 9, 10, 12, 15, 18} # 差集 print( set1 - set3) # >>> {1, 2, 4} print( set1.difference(set3)) # >>> {1, 2, 4} # 对称差 print( set1 ^ set3) # >>>{1, 2, 4, 5, 6, 9, 12, 15, 18} print( set1.symmetric_difference(set3)) # >>> {1, 2, 4, 5, 6, 9, 12, 15, 18} print( (set1 | set3) - (set1 & set3)) # >>> {1, 2, 4, 5, 6, 9, 12, 15, 18} print("------------------------" ) set4 = set() set4.add(31) set4.add(33) set4.add("33") set4.update({34,35,36}) print(set4) set4.discard("33") print(set4) set4.remove(33) print(set4) print( set4.pop() ) print(set4) set4.clear() print(set4) print("------------------") # frozenset 不可变集合,不能添加修改 set5 = frozenset({1,3,5,6}) print(set5)
2023年04月01日
311 阅读
0 评论
0 点赞
2023-03-31
Python 常用网站收藏
安装包国内镜像https://mirrors.huaweicloud.com/python/Mac安装新的python版本https://zhuanlan.zhihu.com/p/665687699
2023年03月31日
300 阅读
0 评论
0 点赞
1
2
3