集合(set)
# s=set('hello')
# print(s)
#
# s=set(['alex','alex','sb'])
# print(s)
# s={1,2,3,4,5,6}
#添加
# s.add('s')
# s.add('3')
# s.add(3)
# print(s)
# s.clear()==>清空
# print(s)
# s1=s.copy()==>拷贝
s={'sb',1,2,3,4,5,6}
#随机删
# s.pop()
#指定删除(remove())
# s.remove('sb')
# s.remove('hellol') #删除元素不存在会报错
# s.discard('sbbbb')#删除元素不存在不会报错discard()
# print(s)
# python_l=['lcg','szw','zjw','lcg']
# linux_l=['lcg','szw','sb']
# p_s=set(python_l)
# l_s=set(linux_l)
# #求交集intersection()
# print(p_s,l_s)
# print(p_s.intersection(l_s))
# print(p_s&l_s)
# #求并集union()
# print(p_s.union(l_s))
# print(p_s|l_s)
# #差集difference()
# print('差集',p_s-l_s)
# print(p_s.difference(l_s))
# print('差集',l_s-p_s)
# print(l_s.difference(p_s))
#交叉补集symmetric_difference()
# print('交叉补集',p_s.symmetric_difference(l_s))
# print('交叉补集',p_s^l_s)
python_l=['lcg','szw','zjw','lcg']
linux_l=['lcg','szw','sb']
p_s=set(python_l)
l_s=set(linux_l)
print(p_s,l_s)
# print('差集',p_s-l_s)
# p_s=p_s-l_s
p_s.difference_update(l_s)
print(p_s)
# s1={1,2}
# s2={2,3,5}
# print(s1.isdisjoint(s2))
s1={1,2}
s2={1,2,3}
print(s1.issubset(s2))#s1 是s2 的子集
print(s2.issubset(s1))#False
print(s2.issuperset(s1))#s1 是s2 的父集
s1={1,2}
s2={1,2,3}
# s1.update(s2) #更新多个值
# s1.add(1,2,3,4) #更新一个值
# s1.union(s2) #不更新
print(s1)
s=frozenset('hello')
print(s)
names=['alex','alex','wupeiqi']
names=list(set(names))
print(names)
# msg='i am %s my hobby is %s' % ('lhf','alex')
# print(msg)
#
# msg='i am %s my hobby is %s' % ('lhf',1)
# msg='i am %s my hobby is %s' % ('lhf',[1,2])
# print(msg)
# name='lhf'
# age=19
# msg='i am %s my hobby is %s' % (name,age)
# print(msg)
#打印浮点数
# tpl = "percent %.2f" % 99.976234444444444444
# print(tpl)
#
# #打印百分比
# tpl = 'percent %.2f %%' % 99.976234444444444444
# print(tpl)
#
# tpl = "i am %(name)s age %(age)d" % {"name": "alex", "age": 18}
# print(tpl)
#
# msg='i am %(name)+60s my hobby is alex' %{'name':'lhf'}
# print(msg)
#
# msg='i am \033[43;1m%(name)+60s\033[0m my hobby is alex' %{'name':'lhf'}
# print(msg)
print('root','x','0','0',sep=':')
# tpl = "i am {name}, age {age}, really {name}".format(name="seven", age=18)
#
# tpl = "i am {name}, age {age}, really {name}".format(**{"name": "seven", "age": 18})
# tpl = "i am {:s}, age {:d}".format(*["seven", 18])
# tpl = "i am {:s}, age {:d}".format("seven", 18) #["seven", 18]
#
# l=["seven", 18]
# tpl = "i am {:s}, age {:d}".format('seven',18)
# print(tpl)
tpl = "numbers: {:b},{:o},{:d},{:x},{:X}, {:%},{}".format(15, 15, 15, 15, 15, 15.87623, 2)
print(tpl)
python_l=['lcg','szw','zjw']
linux_l=['lcg','szw']
python_and_linux_l=[]
for p_name in python_l:
if p_name in linux_l:
python_and_linux_l.append(p_name)
print(python_and_linux_l)
'''
y=2*x+1
x=3
y->7
x=3
y->7
'''
# def test(x):
# '''
# 2*x+1
# :param x:整形数字
# :return: 返回计算结果
# '''
# y=2*x+1
# return y
#
# def test():
# '''
# 2*x+1
# :param x:整形数字
# :return: 返回计算结果
# '''
# x=3
# y=2*x+1
# return y
# a=test()
# print(a)
#过程:就是没有返回值的函数
# def test01():
# msg = 'test01'
# print(msg)
#
#
# def test02():
# msg = 'test02'
# print(msg)
# return msg
#
# def test03():
# msg = 'test03'
# print(msg)
# return 1,2,3,4,'a',['alex'],{'name':'alex'},None
#
# def test04():
# msg = 'test03'
# print(msg)
# return {'name':'alex'}
# t1=test01()
# t2=test02()
# t3=test03()
# t4=test04()
# print(t1)
# print(t2)
# print(t3)
# print(t4)
# def calc(x,y): #x=2,y=3
# res=x**y
# return x
# return y
# res=calc(2,3)
# # print(x)
# # print(y)
# print(res)
# # a=10
# # b=10
# # calc(a,b)
# def test(x,y,z):#x=1,y=2,z=3
# print(x)
# print(y)
# print(z)
#位置参数,必须一一对应,缺一不行多一也不行
# test(1,2,3)
#关键字参数,无须一一对应,缺一不行多一也不行
# test(y=1,x=3,z=4)
#位置参数必须在关键字参数左边
# test(1,y=2,3)#报错
# test(1,3,y=2)#报错
# test(1,3,z=2)
# test(1,3,z=2,y=4)#报错
# test(z=2,1,3)#报错
# def handle(x,type='mysql'):
# print(x)
# print(type)
# handle('hello')
# handle('hello',type='sqlite')
# handle('hello','sqlite')
# def install(func1=False,func2=True,func3=True):
# pass
#参数组:**字典 *列表
def test(x,*args):
print(x)
print(args)
# test(1)
# test(1,2,3,4,5)
# test(1,{'name':'alex'})
# test(1,['x','y','z'])
# test(1,*['x','y','z'])
# test(1,*('x','y','z'))
# def test(x,**kwargs):
# print(x)
# print(kwargs)
# test(1,y=2,z=3)
# test(1,1,2,2,2,2,2,y=2,z=3)
# test(1,y=2,z=3,z=3)#会报错 :一个参数不能传两个值
def test(x,*args,**kwargs):
print(x)
print(args,args[-1])
print(kwargs,kwargs.get('y'))
# test(1,1,2,1,1,11,1,x=1,y=2,z=3) #报错
# test(1,1,2,1,1,11,1,y=2,z=3)
# test(1,*[1,2,3],**{'y':1})
全局变量与局部变量
# name='lhf'
#
#
# def change_name():
# global name
# name='帅了一比'
# print('change_name',name)
#
#
# change_name()
# print(name)
# name='lhf'
#
# def change_name():
# name1='帅了一比'
# name2='帅了一比'
# name3='帅了一比'
# print('change_name',name)
# globals
# NAME = "杠娘"
#
# def yangjian():
# # NAME = "史正文"
# global NAME
# NAME = "小东北"
# print('我要搞', NAME)
#
# def qupengfei():
# # NAME = "基"
# print('我要搞', NAME)
#
# yangjian()
# qupengfei()
# NAME = "产品经理"
#
# def yangjian():
# # NAME = "史正文"
# global NAME # 已经声明,NAME就是全局的的那个变量
# print('我要搞', NAME)
# NAME = "小东北" # 修改 全局的变量
# print('我要搞', NAME)
#
# def qupengfei():
# NAME = "基"
# print('我要搞', NAME)
# 如果函数的内容无global关键字,
# - 有声明局部变量
# NAME = ["产品经理","廖波湿"]
# def qupengfei():
# NAME = "自己"
# print('我要搞', NAME)
# qupengfei()
# - 无声明局部变量
# NAME = ["产品经理","廖波湿"]
# def qupengfei():
# NAME.append('XXOO')
# print('我要搞', NAME)
# qupengfei()
# 如果函数的内容有global关键字
# - 有声明局部变量
# NAME = ["产品经理","廖波湿"]
# def qupengfei():
# global NAME
# NAME = "自己"
# print('我要搞', NAME)
# qupengfei()
# 错误示例
# NAME = ["产品经理","廖波湿"]
# def qupengfei():
# NAME = "自己"
# global NAME
# print('我要搞', NAME)
# qupengfei()
# - 无声明局部变量
# NAME = ["产品经理","廖波湿"]
# def qupengfei():
# global NAME
# NAME = ["阿毛"]
# NAME.append('XXOO')
# print('我要搞', NAME)
# qupengfei()
######## 全局变量变量名大写
######## 局部变量变量名小写
# 优先读取局部变量,能读取全局变量,无法对全局变量重新赋值 NAME=“fff”,
# 但是对于可变类型,可以对内部元素进行操作
# 如果函数中有global关键字,变量本质上就是全局的那个变量,可读取可赋值 NAME=“fff”
# qupengfei()
# yangjian()
# NAME = ["产品经理","廖波湿"]
#
# def yangjian():
# # NAME = "史正文"
# global NAME # 已经声明,NAME就是全局的的那个变量
# print('我要搞', NAME)
# NAME = "小东北" # 修改 全局的变量
# print('我要搞', NAME)
#
# def qupengfei():
# # NAME = "aS"
# NAME.append('天扎龙')
# print('我要搞', NAME)
#
# qupengfei()
# NAME = ["产品经理","廖波湿"]
# def qupengfei():
# name = "自己"
# global NAME
# print('我要搞', NAME)
# qupengfei()
# NAME = '海风'
#
# def huangwei():
# name = "黄伟"
# print(name)
# def liuyang():
# name = "刘洋"
# print(name)
# def nulige():
# name = '沪指花'
# print(name)
# print(name)
# nulige()
# liuyang()
# print(name)
#
# huangwei()
# name = "刚娘"
#
# def weihou():
# name = "陈卓"
# def weiweihou():
# nonlocal name # nonlocal,指定上一级变量,如果没有就继续往上直到找到为止
# name = "冷静"
#
# weiweihou()
# print(name)
#
# print(name)
# weihou()
# print(name)
# # 刚娘
# # 冷静
# 刚娘