一、for循环
names=['egon','jack','lxx','tom','lili']
# print(names[0])
# print(names[1])
# print(names[2])
# print(names[3])
# print(names[4])
# print(len(names))
# count =0
# while count < len(names):
# print(names[count])
# count += 1
# 一:for循环
# 对比while循环,在循环取值这一场景for循环更具优势
# 1、更通用
# 2、更简单
# names=['egon','jack','lxx','tom','lili']
# for x in names: # x = 'jack'
# print(x)
# dic={'k1':111,'k2':222,'k3':333}
# for x in dic:
# print(x,dic[x])
# for x in "hello":
# print(x)
# 二:用for循环控制做事的次数
# count=0
# while count < 3:
# # 做事情
# print('hello')
# count += 1
# for x in "hel":
# print('hello')
# 2.1 for+range
# >>> range(1,5,2) #
# [1, 3]
# for x in range(1,5,2):
# print(x)
# >>> range(1,20,1)
# [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
# for i in range(1,99,1):
# print(i)
# >>>
# >>> range(5)
# [0, 1, 2, 3, 4]
# for i in range(5):
# print(i)
# >>>
# >>> range(1,5)
# [1, 2, 3, 4]
# for i in range(1,5):
# print(i)
# for x in range(100): # x=1
# print('hello')
# for i in range(99):
# print('吴常文很帅!')
# 2.2 加压赋值
# info = [['name',"egon"],['age',18],['gender','male']]
# for x,y in info: # x,y=['name',"egon"]
# print(x,y)
# res = [['name','tom'],['age',19],['sex','male']]
# for x,y in res:
# print(x,y)
# PI = [['姓名','姜琴'],['出生日期','2000-9-12'],['年龄',19],['性别','女']]
# for i,j in PI:
# print(i,j)
# name = input('请输入名字:')
# age = input('请输入年龄:')
# if name == '美女' and age == '19':
# print('姑娘,我们在一起吧!')
# else:
# print('不好意思,我们不适合!')
# 2.3 for+break
# for i in range(10):
# if i == 5:
# break
# print(i)
# for x in range(99):
# if x == 9:
# break
# print(x)
# 2.4 for+continue
# for i in range(10):
# if i == 5:
# continue
# print(i)
# for x in range(21):
# if x == 4:
# continue
# print(x)
# 2.5 for+else
# for i in range(10):
# if i == 5:
# continue
# print(i)
# else:
# print('run。。。')
# for x in range(21):
# if x == 4:
# continue
# print(x)
# else:
# print('run...')
# 2.6 for循环嵌套
# for i in range(3):
# print('=======>loop%s' %i)
# for j in range(5):
# print("inner loop%s" %j)
# for x in range(1,4):
# print('------->第%s自然段'%x)
# for y in range(1,6):
# print('内容%s'%y)
二、可变不可变类型
# 可变类型:值变了,但是内存地址不变,证明就是在改变原值,即原值是可变类型
# l = [111,222,333]
# print(id(l))
# l[0] = 444444
# print(id(l))
# l = ['姜1','姜2','姜3']
# print(id(l))
# l[0] = '姜6'
# print(id(l))
# 不可变类型:值变了,但是内存地址也变了,证明就是产生了新值,即原值是不可变类型
# age = 10
# print(id(age))
# age = 11
# print(id(age))
# x = 170
# print(id(x))
# y = x
# print(id(y))
三、数字类型
'''
# 一:
# ======================================基本使用======================================
# 1、用途:记录年龄、等级、号码、出生年等
# 2、定义方式
age = 10 # age = int(10)
# 数据类型转换
res=int(" 10 ")
print(type(res))
# int("asfdsadfasdf")
# "11" + 10
# 3、常用操作+内置的方法
# ======================================该类型总结====================================
# 存一个值
# 不可变
'''
# 二:float
# ======================================基本使用======================================
# 1、用途:记录薪资、身高、体重等
# 2、定义方式
salary = 3.3 # salary = float(10)
# 数据类型转换
# res=float("10.3")
# print(res+3)
# 3、常用操作+内置的方法
# ======================================该类型总结====================================
# 存一个值
# 不可变
# 进制转换
# print(bin(11)) # 十进制-》二进制
# print(oct(11)) # 十进制-》八进制
# print(hex(11)) # 十进制-》十六进制
四、字符串类型
# ======================================基本使用======================================
# 1、用途:记录描述性质的状态,例如名字、性别、国籍、诗词等
# 2、定义方式:在引号内包含一串字符
name = "egon" # name = str("egon")
# 引号可以是''、""、""" """、''' '''
# 注意1:引号的嵌套
# 注意2:
# file_path='C:a
ew.txt'
# 类型转换:str可以把任意类型都转成字符串类型
# res=str([1,2,3]) # "[1,2,3]"
# print(type(res))
# msg = str(['a','abuse','about'])
# print(msg)
# print(type(msg))
# print(type(str({'k1':111})))
# 3、常用操作+内置的方法
# 3.1 优先掌握的操作:
# 1、按索引取值(正向取+反向取) :只能取
# msg = 'hello world'
# print(msg[0])
# print(msg[-1])
# res = '江山代有才人出,各领风骚数百年'
# print(res[0])
# print(res[-1])
# res = '江山代有才人出,各领风骚数百年'
# print(res[0])
# print(res[-1])
# res[0] = '姜' #报错
# print(res)
# msg[0] = "H"
# 2、切片(顾头不顾尾,步长)===>复制
# msg = 'hello world'
# res = msg[1:5:1] # 1 2 3 4
# print(res)
# print(msg)
# res=msg[1:5:2]
# print(res)
# res = msg[1:5]
# print(res)
# res=msg[1:]
# res=msg[:5]
# res=msg[::1]
# print(id(msg))
# res=msg[:]
# print(id(res))
# print(res)
# msg = 'hello world'
# print(msg[-1:-3:-1]) # -1 -2
# print(msg[-1::-1]) # -1 -2
# print(msg[::-1]) # -1 -2
# msg = '乘风破浪会有时,直挂云帆济沧海'
# res = msg[1:5:1]
# print(res)
# print(msg)
# res = msg[1:6:2]
# print(res)
# msg = '乘风破浪会有时,直挂云帆济沧海'
# res = msg[1:5]
# print(res)
# msg = '乘风破浪会有时,直挂云帆济沧海'
# res = msg[1:]
# print(res)
# res = msg[:]
# print(res)
# res = msg[:6]
# print(res)
# res = msg[::1]
# print(res)
# msg = '乘风破浪会有时,直挂云帆济沧海'
# print(id(msg))
# res = msg[:]
# print(id(res))
# print(id(res))
# print(res)
# msg = '乘风破浪会有时,直挂云帆济沧海'
# print(msg[-1:-3:-1]) # -1 -2
# print(msg[-1::-1]) # -1 -2
# print(msg[::-1]) # -1 -2
# 3、长度len
# msg = 'hello
'
# print(len(msg))
# msg = '曾经沧海难为水,除去巫山不是云
'
# print(len(msg))
# 4、成员运算in和not in
# msg='lxx is sb'
# print('sb' in msg)
# print('sb' not in msg) # 推荐
# print(not 'sb' in msg)
# msg = '爱就爱个彻彻底底'
# print('爱' in msg)
# print('彻彻底底' not in msg)
# print(not '彻彻底底' in msg)
# 5、移除空白strip
# msg='
lxx is sb '
# print(msg)
# res = msg.strip()
# print(res)
# msg = '
真心对真心'
# print(msg)
# res = msg.strip()
# print(res)
# msg = "()=h-,^&*ello*&-=,"
# res = msg.strip("()=-,^&*")
# print(res)
# msg = '[]+-@#$%^&*北京欢迎你@#$%'
# res = msg.strip('[]+-@#$%^&*')
# print(res)
# new_res = res.replace('*-,^&','')
# print(new_res)
# new_res = res.replace('*-@#$%^&','')
# print(new_res)
# msg = "lxx is sb sb is lqz"
# res = msg.replace('sb','SB',1)
# print(res)
# msg = '江湖人称小旋风,大名旋风网'
# res = msg.replace('小旋风','小李子',1)
# print(res)
# 不是所有的功能运行完毕都有返回值
# res = print("hello")
# print(res)
# res = print('撩妹王,大骚哥')
# print(res)
# name = input("your name: ").strip() # name = "egon "
# pwd = input("your password: ").strip()
# if name == "egon" and pwd == "123":
# print('认证成功')
# else:
# print('输入的账号或密码错误')
# username = input('please input your username:').strip()
# password = input('please input your password:').strip()
# if username == '姜琴' and password == '38':
# print('logo successful')
# else:
# print('logo failed')
# msg = '我爱pythonJavaC++'
# res = msg.strip('JavaC++')
# print(res)
# 6、切分split
# info="egon:123:10"
# res = info.split(":",2)
# print(res)
# info = '蒋胜男,将观念,将不胡'
# res = info.split(',')
# print(res)
# join:用来连接字符
# res = ['egon', '123','10']
# msg = ":".join(res) # res是由纯字符串组成的列表
# print(msg)
# res = ['111','222','333','jaker']
# msg = ':'.join(res)
# print(msg)
# 7、循环
# for x in "hello":
# print(x)
# for i in 'successful':
# print(i)
# 3.2 需要掌握的操作:
# 1、strip,lstrip,rstrip
# print("****hello*****".strip('*'))
# print("****hello*****".lstrip('*'))
# print("****hello*****".rstrip('*'))
# print('^^^^^^jaker%%%%%'.strip('^%'))
# print('^^^^^^jaker%%%%%'.lstrip('^%'))
# print('^^^^^^jaker%%%%%'.rstrip('^%'))
# 2、lower,upper
# print("AbcDDDDD".lower())
# print("AbcDDDDD".upper())
# 3、startswith,endswith
# print("hello".startswith("he"))
# print("hello".endswith('llo'))
# 4、format的三种玩法
# 4.1 格式化字符串的方式1:
# x = "egon"
# y = "18"
# msg = "my name is %s my age is %s" %(x,y)
# print(msg)
# i = 'jaker'
# j = '21'
# msg = 'my name is %s my age is %s'%(i,j)
# print(msg)
# 4.2 格式化字符串的方式2:
x = "egon"
y = "18"
# msg = "my name is {} my age is {}".format(x,y)
# msg = "my name is {0} my age is {1}{1}{1}{0}".format(x,y)
# i = 'annl'
# j = '19'
# msg = 'annl name is {} annl age is {}'.format(i,j)
# print(msg)
# msg = 'annl name is {0}{0}{0} annl age is {1}{1}{1}'.format(i,j)
# print(msg)
# msg = "my name is {name} my age is {age}".format(age=18,name="egon")
# print(msg)
# msg = 'my name is {name} my age is {age}'.format(age='17',name='jaker')
# print(msg)
# 4.3 格式化字符串的方式3:
# msg=f"my name is {x} my age is {y}"
# print(msg)
# x = 'jaker'
# y = '18'
# msg=f'my name is {x} my age is {y}'
# print(msg)
# 5、split,rsplit
info='egon:123:10'
# print(info.split(':',))
# print(info.rsplit(':',2))
# msg = 'jsker:321:9'
# print(msg.split(':',2))
# print(msg.rsplit(':',2))
# 8、isdigit:判断字符串是否是由纯数字组成的
# print('18'.isdigit())
# print('18.3'.isdigit())
# print('99'.isdigit()) #True
# print('99.99'.isdigit()) #False
# age = input('your age: ').strip() # age="19"
# if age.isdigit():
# age = int(age)
#
# if age > 18:
# print('too big')
# elif age < 18:
# print('too small')
# else:
# print('right')
# else:
# print("必须输入数字,小垃圾")
# username = input('please input your username:').strip() #输入用户名
# password = input('please input your password:').strip() #输入密码
# if password.isdigit(): #判断密码是否是纯数字
# password = int(password) #转换成int类型
# if username == 'jaker' and password == 18:
# print('logo successful')
# else:
# print('logo failed')
# else:
# print('please input int,thank!')
# 3.3 了解的操作:
# 1、find,rfind,index,rindex,count
msg = "hello sb sb is xxx"
# res = msg.find('sb')
# res = msg.rfind('sb')
# print(res)
# res = msg.find('sbb')
# res = msg.index('sb')
# res = msg.find('sb',0,3)
# print(res)
# res = msg.find('sb')
# print(res)
# res=msg.count('sb',1,8)
# print(res)
msg = '后来的我们没有走到一起,哪怕多年后还爱着你'
# res = msg.find('后来')
# print(res)
# res = msg.rfind('后来')
# print(res)
# res = msg.find('将来')
# print(res) #-1 表示没有该值
# res = msg.index('将来')
# print(res) #substring not found 没有则报错
# res = msg.find('后来',0,2)
# print(res)
# res = msg.rindex('后来')
# print(res)
# res = msg.count('后来',1,8)
# print(res)
# 2、center,ljust,rjust,zfill
name="egon"
# print(name.center(50,'*'))
# print(name.ljust(50,'*'))
# print(name.rjust(50,'*'))
# print(name.rjust(50,'0'))
# print(name.zfill(50))
username = '那些年爱过的女人'
# print(username.center(50,'^')) #两边加^
# print(username.ljust(50,'^')) #右边加^
# print(username.rjust(50,'^')) #左边加^
# print(username.rjust(50,'0')) #左边加0
# print(username.zfill(50)) #左边加0
# 3、expandtabs
# print("hello world")
# print("hello world".expandtabs(1))
# print('hello girlfriend')
# print('hello girlfriend'.expandtabs(1))
# 4、captalize,swapcase,title
msg="hello world egon"
# print(msg.capitalize())
# x="AbCdE"
# print(x.swapcase())
# msg="hello world egon"
# print(msg.title())
# res = 'failure is the mother of success'
# print(res.capitalize()) #首个字母转为大写
# x = 'well wHAT'
# print(x.swapcase()) #大写转为小写,小写转为大写
# res = 'River is lake legend'
# print(res.title()) #首字母全转为大写
# 5、is数字系列
num1=b'4' #bytes
num2='4' #unicode,python3中无需加u就是unicode
num3='四' #中文数字
num4='Ⅳ' #罗马数字
# 5.1 isdigit:bytes中包阿拉伯数字,str内包含阿拉伯数字
# print(num1.isdigit())
# print(num2.isdigit())
# print(num3.isdigit())
# print(num4.isdigit())
# 5.2:str内包含阿拉伯数字、str内包含中文数字、str内包含罗马数字
# print(num1.isalnum())
# print(num2.isnumeric())
# print(num3.isnumeric())
# print(num4.isnumeric())
# 5.3: str内包含阿拉伯数字、
# print(num2.isdecimal())
# print(num3.isdecimal())
# print(num4.isdecimal())
# num1 = b'4' #bytes
# num2 = '4' #unicode,python3中无需加u就是unicode
# num3 = '四' #中文数字
# num4 = 'Ⅳ' #罗马数字
# print(num1.isdigit())
# print(num2.isdigit())
# print(num3.isdigit())
# print(num4.isdigit())
# print(num1.isalnum())
# print(num2.isalnum())
# print(num3.isalnum())
# print(num4.isalnum())
# print(num1.isdecimal())
# print(num2.isdecimal())
# print(num3.isdecimal())
# print(num4.isdecimal())
# 6、is其他
# name='egoN'
# print(name.isalnum()) #字符串由字母或数字组成
# print(name.isalpha()) #字符串只由字母组成
# name="input"
# print(name.isidentifier())
# name="EGON123"
# print(name.islower())
# print(name.isupper())
# name=" "
# print(name.isspace())
# name="My Name Is Egon"
# print(name.istitle())
# name = 'Your ability determines your development'
# print(name.isalnum()) #字符串有字母或数字组成
# print(name.isalpha()) #字符串只由字母组成
# name = 'input'
# print(name.isidentifier())
# name = 'JAKER123'
# print(name.islower())
# print(name.isupper())
# name = ' '
# print(name.isspace())
# name = 'My Age Is 19'
# print(name.istitle())
# ======================================该类型总结====================================
# 存一个值
# 有序
# 不可变
五、列表类型
# ======================================基本使用======================================
# 1、用途:按照位置存放多个值
# 2、定义方式:在[]用逗号分割开多个任意类型的值
# l = [11,22,33] # l = list([11,22,33] )
# print(type(l))
# 数据类型转换
# res = list('hello')
# print(res)
# 3、常用操作+内置的方法
# 3.1 优先掌握的操作:
# 1、按索引存取值(正向存取+反向存取):可取可改, 只能针对已经存在的索引改值
# l = [11, 22, 33]
# print(l[0])
# print(l[-1])
#
# l[0] = 1111111
# print(l)
# 2、切片(顾头不顾尾,步长)=>拷贝
# l=[11,22,33,44,55]
# res=l[0:5:2]
# print(res)
# print(l)
l = [11, 22, 33]
# print(l[::-1])
# new_l = l[:]
# print(new_l[0])
# new_l[0]=444
# print(new_l[0])
# print(l[0])
# src_l = [11, 22, [33, 44]]
# dst_l=src_l[:] # 浅copy
# dst_l=src_l.copy() # 浅copy
# from copy import deepcopy
# dst_l = deepcopy(src_l) # 深copy
# dst_l[0]=66666
# print(dst_l)
# print(src_l)
# dst_l[2][0] = 777
# print(dst_l)
# print(src_l)
# print(id(src_l[0]),id(src_l[1]),id(src_l[2]))
# print(id(dst_l[0]),id(dst_l[1]),id(dst_l[2]))
# 3、长度
# src_l = [11, 22, [33, 44]]
# print(len(src_l))
# 4、成员运算in和not in
# src_l = [11, 22, [33, 44]]
# print([33, 44] in src_l)
# print([44, 33] in src_l)
# 5、追加插入extend
src_l = [11, 22, 33]
# src_l[3] = 111111 # 报错
# res=src_l.append(44) #append只是单纯地往列表末尾添加值,该功能本身没有返回值
# src_l.append(55)
# print(src_l)
# print(res)
# src_l.insert(0,'aaa')
# print(src_l)
# names=['egon','jack','tom']
# for name in names:
# src_l.append(name)
# src_l.extend(names)
# src_l.extend("hello")
# print(src_l)
# 6、删除
names = ['egon', 'jack', 'tom']
# 方式1:万能删除,没有返回值===》单纯的删
# del names[0]
# 方式2:remove指定元素删除,没有返回值===》单纯的删
# res = names.remove('tom')
# print(res)
# 方式3:pop指定索引删除,有返回===》取走
# res=names.pop(1)
# print(res)
# 7、循环
# names=['egon','jack','tom']
# for name in names:
# print(name)
# 3.2 需要掌握的操作:
# names = [11, 22, 'egon', "egon", 'jack','egon', 'tom']
# print(names.count("egon"))
# res = names.index('egon')
# res = names.index('egon111')
# print(res)
# names.clear()
# print(names)
# names.reverse()
# names=names[::-1]
# print(names)
# names = [-3,-5,10,4]
# names.sort(reverse=True)
# print(names)
# ======================================该类型总结====================================
# 存多个值
# 有序
# 可变
# 案列:
# 一: 队列:先进先出FIFO
q=[]
# 入队
# q.append('first')
# q.append('second')
# q.append('third')
# 出队
# print(q.pop(0))
# print(q.pop(0))
# print(q.pop(0))
# 堆栈:后进先出LIFO
t=[]
# 入栈
t.append('first')
t.append('second')
t.append('third')
# 出栈
print(t.pop())
print(t.pop())
print(t.pop(-1))
六、元组类型
# 元组就是一个不可变的列表
# ======================================基本使用======================================
# 1、用途:按照位置存放多个任意类型的元素
# 2、定义方式:()内用逗号分隔开多个任意类型的值
# t = (11, 22, 33) # t = tuple((11, 22, 33))
# print(type(t))
# 注意: 如果元组只有一个元素.那么必须加一个逗号
# x=(10,) #
# print(type(x))
# 数据类型转换
# res=tuple([666,777])
# print(res,type(res))
# 3、常用操作+内置的方法
#优先掌握的操作:
#1、按索引取值(正向取+反向取):只能取
# t=(11,22,33)
# t[0]=6666
#2、切片(顾头不顾尾,步长)
#3、长度
#4、成员运算in和not in
#5、循环
# t=(11,22,33)
# ======================================该类型总结====================================
# 存多个值
# 有序
# 不可变
# t=(11,22,[33,44])
# print(id(t[0]),id(t[1]),id(t[2]))
# t[2]=666
# t[2][0]=333333333333333333333
# print(t)
# print(id(t[0]),id(t[1]),id(t[2]))
七、字典类型
# ======================================基本使用======================================
# 1、用途:按照属性存放多个值
# 2、定义方式:在{}内用逗号分隔开多个key:value
# 其中value可以是任意类型
# 而key必须是不可变的类型,通常为字符串类型,并且key不能重复
#
# d = {111:"xxx",3.1:"yyy",[1,2,3]:"zzz"}
# d = {'k1':111,'k1':222,'k1':3333}
# print(d)
# dic = {'name':'egon','age':18} # dic=dict(...)
# 数据类型转换
# t=[('name','egon'),('age',18)]
# res=dict(t)
# print(res)
# res = dict(a=1, b=2, c=3)
# print(res)
# keys=['name','age','gender']
# res={}.fromkeys(keys,None)
# print(res)
# 3、常用操作+内置的方法
# 3.1 优先掌握
# 1、按key存取值:可存可取
# dic = {'name':'egon','age':18}
# print(dic['name'])
# print(dic['nameasdfadf'])
# res=dic.get('name')
# print(res)
# key不存在则加元素,存在则改值
# dic['gender'] = 'male'
# print(dic)
# 2、长度len
# dic = {'name':'egon','age':18}
# print(len(dic))
# 3、成员运算in和not in=>依据key
# dic = {'name':'egon','age':18}
# print('name' in dic)
# print('egon' in dic)
# 4、删除
dic = {'name': 'egon', 'age': 18}
# 方式1:万能删除,没有返回值
# del dic['name']
# print(dic)
# 方式2:pop指定key删除,返回删除的value
# res = dic.pop('name')
# print(res)
# 方式3:popitem
# res=dic.popitem()
# print(res)
# 5、键keys(),值values(),键值对items()
# dic = {'name':'egon','age':18}
# dic.keys()
# C:Users11764>python2
# Python 2.7.18 (v2.7.18:8d21aa21f2, Apr 20 2020, 13:25:05) [MSC v.1500 64 bit (AMD64)] on win32
# Type "help", "copyright", "credits" or "license" for more information.
# >>>
# >>> dic = {'name':'egon','age':18}
# >>> dic
# {'age': 18, 'name': 'egon'}
# >>>
# >>> dic.keys()
# ['age', 'name']
# >>> dic.values()
# [18, 'egon']
# >>> dic.items()
# [('age', 18), ('name', 'egon')]
# >>>
# 6、循环
# dic = {'name':'egon','age':18}
# for k in dic.keys():
# print(k)
# print(list(dic.keys()))
# for v in dic.values():
# print(v)
# for k,v in dic.items():
# print(k,v)
# 3.1 需要掌握
# dic={'k1':111,'k2':2222}
# dic.update({"k2":4444,'k3':5555})
# print(dic)
dic={'age':18}
#
# # if 'name' not in dic:
# # dic['name']="EGON"
#
# res = dic.setdefault('name',"EGON")
# # print(dic)
# print(res)
# ======================================该类型总结====================================
# 存多个值
# 无序
# 可变
八、集合类型
# 集合类型set
# ======================================基本使用======================================
# 1、用途
# (1)去重
# (2) 关系运算
# 2、定义方式:在{}内用逗号分割开多个元素,其中元素的特点为
# (1)所有的元素必须是不可变类型
# (2)集合内元素不能重复
# (3)集合内元素无序
# s={123,123,123,123,333,4444,555} # s = set(...)
# print(s)
# 数据类型转换:
# print(set('hello'))
# print(set([11,11,11,22,[33,44]])) # 报错:无法把可变类型放入集合
# 3、常用操作+内置的方法
# 3.1 去重
# names=['egon','egon','egon',18,18,18,10]
# names=list(set(names))
# print(names)
# 示范
# infos = [
# {'name': 'egon', 'age': 18, 'sex': 'male'},
# {'name': 'jack', 'age': 73, 'sex': 'male'},
# {'name': 'tom', 'age': 20, 'sex': 'female'},
# {'name': 'egon', 'age': 18, 'sex': 'male'},
# {'name': 'egon', 'age': 18, 'sex': 'male'},
# ]
# l = []
# for info in infos:
# if info not in l:
# l.append(info)
#
# print(l)
# 3.2 关系运算
# 3.2.1 自己写代码做关系运算
# python_stus=["张三",'egon','jack','lili','李四']
# linux_stus=['李大炮','李二炮','jack','lili','王三炮']
#
# l=[]
# for stu in python_stus:
# if stu in linux_stus:
# l.append(stu)
# print(l)
# 3.2.2 集合的关系运算
python_stus = {"张三", 'egon', 'jack', 'lili', '李四'}
linux_stus = {'李大炮', '李二炮', 'jack', 'lili', '王三炮'}
# (1)交集:既报名python又报名linux的学员
# res=python_stus & linux_stus
# print(res)
# res=python_stus.intersection(linux_stus)
# print(res)
# (2)并集:上海校区所有的学员姓名
# res=python_stus | linux_stus
# print(res)
# res=python_stus.union(linux_stus)
# print(res)
# (3)差集:只报名python的学员
# res = python_stus - linux_stus
# print(res)
# res = python_stus.difference(linux_stus)
# print(res)
# res = linux_stus - python_stus
# print(res)
# (4) 对称差集: 只报名python的学员和只报名了linux的学员
# res = (python_stus - linux_stus) | (linux_stus - python_stus)
# res = linux_stus ^ python_stus
# print(res)
# res= linux_stus.symmetric_difference(python_stus)
# print(res)
# (5) 父子集:包含与被包含的关系
# 包含才能比大小
# s1={1,2,3}
# s2={1,2}
# print(s1.issuperset(s2))
# print(s2.issubset(s1))
# print(s1 >= s2) # 如果s1包含s2则成立,称之为s1是s2他爹
# print(s2 <= s1) # 如果s1包含s2则成立,称之为s1是s2他爹
# 3.3 其他了解操作
# s1={1,2,3}
# s2={1111,2,3,333333}
#
# s1.intersection_update(s2) # s1=s1.intersection(s2)
# print(s1)
# s1={1,2,3}
# s1.update({3,4,5})
# print(s1)
# s1={1,2,3}
# res=s1.pop()
# print(res,s1)
# s1={1,2,3}
# res=s1.remove(3)
# print(res)
# print(s1)
# s1={1,2,3}
# s1.add("hello")
# print(s1)
# # s1.update("hello")
# # print(s1)
# s1={1,2,3}
# s2={54,4,6}
# print(s1.isdisjoint(s2))
# s1={1111,2222,333}
# s1.discard(444) # 删除的元素不存在也不会报错
# print(s1)
# s1.remove(444)
# ======================================该类型总结====================================
# 存多个值
# 无序
# 可变