#-----深浅拷贝----
 import copy

 a = ["xiaoming",111,[5000,2000]]
b = a
print("b:%s" % b) #a,b共享同一块内存地址,输出结果b:['xiaoming', 111, [5000, 2000]] #浅拷贝只拷贝第一层,第二层指针指向共享[5000,2000]
c = a.copy() #浅拷贝
c[0] = "xiaowang"
c[1] = 222
a[2][1] -= 300
print("c:%s" % c) #c:['xiaowang', 222, [5000, 1700]] d = copy.copy(a) #浅拷贝
d[0] = "xiaoyang"
d[1] = 333
d[2][1] -= 700
print("d:%s"% d) #d:['xiaoyang', 333, [5000, 1000]] #深拷贝,克隆相同的一份
e = copy.deepcopy(a) #深拷贝
e[2][1] += 1000
print("e:%s" % e) #e:['xiaoming', 111, [5000, 2000]]


#----集合(set)-----

#集合把不同的元素组合在一起
 a = set("python project")
print(a) #{'c', ' ', 'p', 'e', 'h', 'j', 'y', 'o', 't', 'r', 'n'}
b = set(["python","linux","java","linux"])
print(b,type(b)) #{'python', 'java', 'linux'} <class 'set'> #set去重
print(list(b)) #['java', 'linux', 'python'] #转为列表
#集合对象是一组无序排列可哈西的值,集合成员可以做字典的键
 li = [[1,2],'a','b']
s = set(li)
print(s) #TypeError: unhashable type: 'list' a = [1,2,"a","z"]
b = set(a)
c = {"info":b}
print(c) #{'info': {'a', 1, 2, 'z'}}
#集合分类:可变集合、不可变集合
#可变集合(set):可添加和删除元素,集合(set)是非可哈希的,不能用做字典的键,也不能做其他集合的元素。
#不可变集合(frozenset) 不能添加和删除
#创建集合
 a1 = set(("test","hello"))
print(a1) #{'test', 'hello'}
#访问集合
 #-----in,not in 判断是否在集合中
a2 = set(["dream","rise",1,2,4])
print("dream" in a2) #True
print("rise" not in a2) #False
#-----for 循环遍历
 for i in a2:
print(i)
#集合中添加、修改、删除元素
 #-----add 添加
a2.add("uu")
print(a2) #{1, 2, 'uu', 4, 'dream', 'rise'} #-----update 更新
a2.update("abs")
print(a2) #{1, 2, 4, 'dream', 'a', 'rise', 'uu', 's', 'b'} a3 = {1, 2, 4, 'dream', 'rise'}
a3.update([12,"hello",1])
print(a3) #{1, 2, 'hello', 4, 12, 'rise', 'dream'} #-----删除
a3.remove(1)
print(a3) #{'dream', 2, 4, 12, 'hello', 'rise'} a3.pop() #随机删除
print(a3) #{4, 12, 'dream', 'rise', 'hello'} a3.clear() #清空集合
print(a3) del a2 #删除集合
print(a2)

#-----集合操作-----
 #集合等价于不等价
print(set("test") == set("tesssssttt")) #等价 #True
print(set("test")!= set("tesssssttt")) a = set([1,2,3,4,5,6,7])
b = set([3,4,5,6,7,8,9]) print(a & b) #交集{3, 4, 5, 6, 7}
print(a | b) #并集{1, 2, 3, 4, 5, 6, 7, 8, 9}
print(a - b) #差集{1, 2}
print(b - a) #差集{8, 9}
print(a ^ b) #对称差集{1, 2, 8, 9} #-----子集、超集(父集)
print(a > b)
print(a < b)
#-----函数-----
#-----作用:
1、减少重复代码
2、方便修改
3、保持代码一致性 #-----函数的命名规则:
1、函数名必须以下划线或字母开头,可以包含任意字母、数字或下划线组合。
2、不能使用任何的标点符号
3、函数名是区分大小写
4、函数名不能是保留字 #-----形参和实参
形参:形式参数,不是实际存在,是虚拟变量。
实参:实际参数,电泳函数时传给函数的参数。

#-----logging模块-----
 import logging

 logger = logging.getLogger() #创建logger对象

 fh = logging.FileHandler('test.log') #创建文件输出对象

 sh = logging.StreamHandler() #创建屏幕输出对象

 formater = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')

 fh.setFormatter(formater)
sh.setFormatter(formater) logger.addHandler(fh) #添加文件输出
logger.addHandler(sh) #添加屏幕输出 logger.setLevel(logging.WARNING) #添加日志级别 logger.debug('debug message1')
logger.info('info message2')
logger.warning('warning message3')
logger.error('error message4')
logger.critical('critical message5')
#-----logging屏幕输出、文件写入日志信息-----
 2019-09-24 16:48:27,485 - root - WARNING - warning message3
2019-09-24 16:48:27,485 - root - ERROR - error message4
2019-09-24 16:48:27,486 - root - CRITICAL - critical message5

最新文章

  1. Linux初学:(一)Linux概述
  2. 评论Final版本发布
  3. git 日志格式化
  4. [转载] LinkedIn架构这十年
  5. 大规模Hadoop集群实践:腾讯分布式数据仓库(TDW)
  6. flume学习安装
  7. nginx+keepalived+tomcat之tomcat性能调优
  8. NGUI使用教程(3) 使用外部图片制作Atlas(图集)
  9. Java中SJBArrayList自己简单实现ArrayList
  10. re模块的结果小练习题
  11. Java 故障安全异常处理
  12. HNの野望
  13. myeclipse、maven、tomcat、jdk技巧和坑【待完善】
  14. yum安装失败:ublic key for **.rpm is not installed
  15. Java常用系统变量收集
  16. IIS7 windows 下安装PHP
  17. 3-1 LVS-NAT集群
  18. oracle EBS grant 您不具有执行当前操作的足够权限。请与您的系统管理员联系。
  19. POJ 1095
  20. mybatis第二天——动态SQL与关联查询

热门文章

  1. 11/10 &lt;priorityQueue&gt; 215 347
  2. [LeetCode] 241. Different Ways to Add Parentheses 添加括号的不同方式
  3. .NET Core:跨域
  4. rsync用法
  5. 深入V8引擎-AST(5)
  6. PyTorch中MaxPool的ceil_mode属性
  7. JS提交表单页面不跳转、JS下载、动态创建from
  8. vue基础之data
  9. layui提示框事件
  10. 2019 vs 如何升级到.net core 3.0 版本