python整理-Day3

set

无须,不重复,可嵌套的集合

  1 class set(object):
  2     """
  3     set() -> new empty set object
  4     set(iterable) -> new set object
  5
  6     Build an unordered collection of unique elements.
  7     """
  8     def add(self, *args, **kwargs): # real signature unknown
  9         """
 10         Add an element to a set,添加元素
 11
 12         This has no effect if the element is already present.
 13         """
 14         pass
 15
 16     def clear(self, *args, **kwargs): # real signature unknown
 17         """ Remove all elements from this set. 清除内容"""
 18         pass
 19
 20     def copy(self, *args, **kwargs): # real signature unknown
 21         """ Return a shallow copy of a set. 浅拷贝  """
 22         pass
 23
 24     def difference(self, *args, **kwargs): # real signature unknown
 25         """
 26         Return the difference of two or more sets as a new set. A中存在,B中不存在
 27
 28         (i.e. all elements that are in this set but not the others.)
 29         """
 30         pass
 31
 32     def difference_update(self, *args, **kwargs): # real signature unknown
 33         """ Remove all elements of another set from this set.  从当前集合中删除和B中相同的元素"""
 34         pass
 35
 36     def discard(self, *args, **kwargs): # real signature unknown
 37         """
 38         Remove an element from a set if it is a member.
 39
 40         If the element is not a member, do nothing. 移除指定元素,不存在不保错
 41         """
 42         pass
 43
 44     def intersection(self, *args, **kwargs): # real signature unknown
 45         """
 46         Return the intersection of two sets as a new set. 交集
 47
 48         (i.e. all elements that are in both sets.)
 49         """
 50         pass
 51
 52     def intersection_update(self, *args, **kwargs): # real signature unknown
 53         """ Update a set with the intersection of itself and another.  取交集并更更新到A中 """
 54         pass
 55
 56     def isdisjoint(self, *args, **kwargs): # real signature unknown
 57         """ Return True if two sets have a null intersection.  如果没有交集,返回True,否则返回False"""
 58         pass
 59
 60     def issubset(self, *args, **kwargs): # real signature unknown
 61         """ Report whether another set contains this set.  是否是子序列"""
 62         pass
 63
 64     def issuperset(self, *args, **kwargs): # real signature unknown
 65         """ Report whether this set contains another set. 是否是父序列"""
 66         pass
 67
 68     def pop(self, *args, **kwargs): # real signature unknown
 69         """
 70         Remove and return an arbitrary set element.
 71         Raises KeyError if the set is empty. 移除元素
 72         """
 73         pass
 74
 75     def remove(self, *args, **kwargs): # real signature unknown
 76         """
 77         Remove an element from a set; it must be a member.
 78
 79         If the element is not a member, raise a KeyError. 移除指定元素,不存在保错
 80         """
 81         pass
 82
 83     def symmetric_difference(self, *args, **kwargs): # real signature unknown
 84         """
 85         Return the symmetric difference of two sets as a new set.  对称差集
 86
 87         (i.e. all elements that are in exactly one of the sets.)
 88         """
 89         pass
 90
 91     def symmetric_difference_update(self, *args, **kwargs): # real signature unknown
 92         """ Update a set with the symmetric difference of itself and another. 对称差集,并更新到a中 """
 93         pass
 94
 95     def union(self, *args, **kwargs): # real signature unknown
 96         """
 97         Return the union of sets as a new set.  并集
 98
 99         (i.e. all elements that are in either set.)
100         """
101         pass
102
103     def update(self, *args, **kwargs): # real signature unknown
104         """ Update a set with the union of itself and others. 更新 """
105         pass 

练习:


#!/usr/bin/env python# -*- coding: utf-8 -*-# Author:wzc

dic1={    "a":"8",    "b":"4",    "d":"2",}

dic2={    "a":"4",    "b":"4",    "c":"2",}

old_dic=set(dic1)print(old_dic)new_dic=set(dic2)print(new_dic)add_key=old_dic.difference(new_dic)print(add_key)del_key=new_dic.difference(old_dic)print(del_key)up_key=list(old_dic.intersection(new_dic))print(up_key)for i in list(up_key):    #print(dic1[i],dic2[i])    if dic1[i] != dic2[i]:        print(i)

展示结果:

{‘a‘, ‘d‘, ‘b‘}
{‘a‘, ‘c‘, ‘b‘}
{‘d‘}
{‘c‘}
[‘a‘, ‘b‘]
a

函数

定义和使用

函数的定义主要有如下要点:

  • def:表示函数的关键字
  • 函数名:函数的名称,日后根据函数名调用函数
  • 函数体:函数中进行一系列的逻辑计算,如:发送邮件、计算出 [11,22,38,888,2]中的最大数等...
  • 参数:为函数体提供数据
  • 返回值:当函数执行完毕后,可以给调用者返回数据。
时间: 2024-11-14 11:24:22

python整理-Day3的相关文章

python s12 day3

python s12 day3 深浅拷贝 对于 数字 和 字符串 而言,赋值.浅拷贝和深拷贝无意义,因为其永远指向同一个内存地址. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 import copy # ######### 数字.字符串 ######### n1 = 123 # n1 = "i am alex age 10" print(id(n1)) # ## 赋值 ## n2 = n1 print(id(n2)) # ## 浅拷贝 ## n2 = cop

Python学习day3作业

Python学习day3作业 days3作业 作业需求     HAproxy配置文件操作 根据用户输入,输出对应的backend下的server信息 可添加backend 和sever信息 可修改backend 和sever信息 可删除backend 和sever信息 操作配置文件前进行备份 添加server信息时,如果ip已经存在则修改;如果backend不存在则创建:若信息与已有信息重复则不操作 [x] 博客 [x] 查询backend下的server信息 [x] 添加backend和se

Python整理开发环境搭建

Python整理环境搭建,不仅仅包括Python版本的安装,还包括Python命令行,setuptools安装,和工作环境配置等. 1. Python版本的安装 Python的安装 >>> Window下的安装,配置挺简单,稍微注意点的是,PATH配置 >>> Linux 下的安装,大致遵循下面的安装顺序. 网上可以找到很多,Python的安装配置(Windows和Linux下): http://weixiaolu.iteye.com/blog/1617440 安装Mi

python初识-day3

1.字符串常用操作(较多,用代码加注释表示) 1 name = '\tMy name is congcong' 2 print(name.capitalize())#输出结果为 My name is congcong(首字母大写) 3 print(name.count('n')) #输出结果为 3(统计) 4 print(name.center(30,'-')) #输出结果为 -----My name is congcong------(一共打印30个字符,并将字符串放中间) 5 print(n

Python 整理一

---恢复内容开始--- Python (pailen)最近学习这个语言,其实早在几年前学习perl的时候就知道有这个语言了,在讲perl的那本书后面就推荐学习python,并且还附加了二章的入门.当时初看了一下,发现和perl很相似. 这几天学了python的一些基本东西,整理一下.如下 : #!/usr/bin/python ''' 3.XX版后,默认是UTF-8,支持中文了. ''' #coding=utf-8 '''这是注释,和Perl一样可以使用#号注释单行,但是多行注释是使用3个单引

python之day3(文件操作、字符转码、函数)

文件操作 f=open("yesterday","r",encoding="utf-8")  #以只读模式打开文件 data=f.read()                             #读取所有内容 data2=f.read()                       #读取所有内容 print(data)                          #再次读取所有内容 print("-------------

Python基础day-3

变量的组成: 变量由变量名,赋值符号,变量值三部分组成,变量还分类型. 变量名→n = 1←变量值    ↑ 赋值符号 比较方法: 身份比较:比较的是变量值的id >>> x = 300 >>> id(x) 46137936 >>> y = 300 >>> id(y) 46137984 >>> x is y False >>> 值比较:比较两个变量值 >>> x = 300 >

初学python之day3

又学习新东西了,赶紧记下来. 一. python学习之对文件的读写操作 1-1 对文件的操作顺序: 1  变量 = open(...) 2 操作文件的读写 3 关闭文件 1-2 打开文件的模式 r,只读模式(默认). input = open('data', 'r')        也可写成  input = open('data') w,只写模式.(不可读:不存在则创建:存在则删除内容:)a,追加模式.(可读: 不存在则创建:存在则只追加内容:) "+" 表示可以同时读写某个文件:

python整理-day9

1.TCP/IP tcp/ip协议的英文全名:Transmission control protocol and internet protocol tcp/ip协议是主机接入互联网以及接入互联网的两台主机通信额标准 1.物理层(Physical Layer) 物理层规定了激活.维持.关闭通信端点之间的机械特性.电气特性.功能特性以及过程特性.该层为上层协议提供了一个传输数据的物理媒体. 在这一层,数据的单位称为比特(bit). 属于物理层定义的典型规范代表包括:EIA/TIA RS-232.E