模块(深浅copy)、第三方模块的下载
1.Python解释器和Pycharm的下载及部分使用2.Pycharm的使用和python的部分原理逻辑3.Python语法入门4.基本运算符和流程控制5.流程控制和一些字符串内部读取关键词或格式6.字符串、列表内置方法和可变类型、不可变类型7.字典、元组、集合内置方法和集合的运算8.字符编码和文件操作9.文件操作和操作模式10.文件操作和函数11.装饰器12.迭代器和异常捕捉13.装饰器补充(算法)14.生成器15.模块16.模块的导入、包、规范书写17.正则表达式和re模块18.模块(time、datetime、random、sys)19.模块(os、json、pickle)20.模块(subrocess、hashilb、日志模块)
21.模块(深浅copy)、第三方模块的下载
22.面向过程、面向对象、类23.面向对象(绑定方法、非绑定方法、隐藏属性、property装饰器)24.面向对象(三大特征、继承下的查找、super、组合)25.面向对象(魔术方法、反射、异常、minins)深浅copy
导入模块 # 这个简单就浅浅复制一下就行了
import copy
1.浅copy
浅copy就是将旧的值从右到左的通过赋值给新的变量,虽然他们的值相等了但是内存地址并不相等,改变一个另外一个不会发生改变,但如果容器里面嵌套容器时,改变被嵌套容器内的内容,另外一个会随之发生改变
2.深copy
深copy就是通过copy函数,将一个变量复制到另外一个变量上,他们的内存地址和内容都一模一样,但和浅copy相反的是,当改变容器内的单个元素,另外一个变量会随之改变,但如果容器内嵌套了容器,改变容器内的值,另外一个并不会发生变化
# list1 = [1, 2, 3] # list2 = list(list1) # # list2 = list1 # print(list2) # print("list1==list2 ?", list1 == list2) # list1==list2 ? True # print("list1 is list2 ?", list1 is list2) # list1 is list2 ? False # set1= set([1, 2, 3]) # # set2 = set(set1) # print(set2) # print("set1==set2 ?",set1==set2) # set1==set2 ? True # print("set1 is set2 ?",set1 is set2) # set1 is set2 ? False # dict1 = {1: [1, 'w'], 2: 0, 3: 98} # dict2 = dict(dict1) # print(dict2) # print("dict1 == dict2 ?", dict1 == dict2) # dict1 == dict2 ? True # print("dict1 is dict2 ?", dict1 is dict2) # dict1 is dict2 ? False # list1 = [1, 2, 3] # list2 = list1[:] # print(list2) # print("list1 == list2 ?",list1 == list2) # print("list1 is list2 ?",list1 is list2) import copy # list1 = [1, 2, 3] # list2 = copy.copy(list1) # print(list2) # print("list1 == list2 ?",list1 == list2) # list1 == list2 ? True # print("list1 is list2 ?",list1 is list2) # list1 is list2 ? False # set1 = {1, 2, 3} # set2 = copy.copy(set1) # print(set2) # print("set1 == set2 ?",set1 == set2) # set1 == set2 ? True # print("set1 is set2 ?",set1 is set2) # set1 is set2 ? False # dict1 = {1:'xiaoming', 2:'xiahua',3:'xiaoli'} # dict2 = dict(dict1) # print(dict2) # print("dict1 == dict2 ?",dict1 == dict2) # print("dict1 is dict2 ?",dict1 is dict2) # tuple1 = (1, 2, 3) # tuple2 = tuple(tuple1) # print(tuple2) # print("tuple1 == tuple2 ?",tuple1 == tuple2) # tuple1 == tuple2 ? True # print("tuple1 is tuple2 ?",tuple1 is tuple2) # tuple1 is tuple2 ? True # # # # tuple1 = (1, 2, 3) # tuple2 = tuple1[:] # print(tuple2) # print("tuple1 == tuple2 ?",tuple1 == tuple2) # Ture # print("tuple1 is tuple2 ?",tuple1 is tuple2) # Ture # str1 = 'operation' # str2 = str1[:] # print(str2) # print("str1 == str2 ?",str1 == str2) # True # print("str1 is str2 ?",str1 is str2) # True import copy # from copy import copy # from copy import deepcopy # # copy() # deepcopy() a = [1, [2, 3, [5, 6]]] # [1, [2, 3, 4]] b = copy.deepcopy(a) # [1, [2, 3]] c = copy.copy(a) # [1, [2, 3, 4]] a[1][2].append(7) print(a) # [1, [2, 3, 4]] print(b) # [1, [2, 3]] print(c) # [1, [2, 3, 4]] # # import requests # # requests.get('')
第三方模块的使用
# 并不是python自带的 需要基于网络下载!!! '''pip所在的路径添加环境变量''' 下载第三方模块的方式 方式1:命令行借助于pip工具 pip3 install 模块名 # 不知道版本默认是最新版 pip3 install 模块名==版本号 # 指定版本下载 pip3 install 模块名 -i 仓库地址 # 临时切换 '''命令行形式永久修改需要修改python解释器源文件''' 方式2:pycharm快捷方式 settings project project interprter 双击或者加号 点击右下方manage管理添加源地址即可 # 下载完第三方模块之后 还是使用import或from import句式导入使用 """ pip命令默认下载的渠道是国外的python官网(有时候会非常的慢) 我们可以切换下载的源(仓库) (1)阿里云 http://mirrors.aliyun.com/pypi/simple/ (2)豆瓣 http://pypi.douban.com/simple/ (3)清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/ (4)中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/ (5)华中科技大学http://pypi.hustunique.com/ pip3 install openpyxl -i http://mirrors.aliyun.com/pypi/simple/ """ """ 下载第三方模块可能报错的情况及解决措施 1.报错的提示信息中含有关键字timeout 原因:网络不稳定 措施:再次尝试 或者切换更加稳定的网络 2.找不到pip命令 环境变量问题 3.没有任何的关键字 不同的模块报不同的错 原因:模块需要特定的计算机环境 措施:拷贝报错信息 打开浏览器 百度搜索即可 pip下载某个模块报错错误信息 """
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)