字符串类型
#name='egon'
# print(id(name),type(name),name)
# #优先掌握的操作:
# # 按索引取值(正向取+反向取) :只能取
# print(name[0],type(name[0]))
#print(name[-3])#反向取值,到第一个为-1
# # 切片(顾头不顾尾,步长)
#print(name[1:3])
# msg='hello world'
# print(msg[3:5])
# print(msg[1:4:3])#头:尾:步长
#msg='abcdefgh'#aceg
#print(msg[0:7:2])
#print(msg[5:1:-2])#从右往左取值
# 长度len
# msg=10#数字是一个整体,不能看长度值
# print(len(msg))
# msg='abc'
# print(len(msg))
# 成员运算in和not in
# msg='hello world'
# print('h' in msg)
# 移除空白strip
# password='1234abcd '
# print(password.strip())#移除空格
# msg='1111111haha111111'
# print(msg.strip('1'))
# 切分split
# usr_info='root:x:0:0::root:/bin/bash'
# print(usr_info.split(':')[5])#取第5个值
# print(usr_info.split(':',1))#切分1次
# cmd='put a.txt'
# print(cmd.split()[1])#默认按照空格切分
# filepath='put /a/b/c/d/a.txt'
# print(filepath.split('/',5))
# 循环
#其他操作
##.strip去掉不想要的部分
# msg='******hahaha******'
# print(msg.strip('*'))#去掉*
# print(msg.lstrip('*'))#去掉左边的*
# print(msg.rstrip('*'))#去掉右边的*
##.startswith判断以某个字符开头,endswith判断以某个字符结尾
# msg='alex'
# print(msg.startswith('a'))#判断是否以a开头
# print(msg.endswith('x'))#判断是否以x结尾
##.replace 替换字符
# msg='hello world'
# print(msg.replace('l','e',1))#把l替换成e,后面的数字代表替换几次,不写默认全部替换
##.format
# print('my name is %s my age is %s' %('egon',18))
# print('my name is {} my age is {}'.format('egon',18))
# print('{0} {1} {0}'.format('egon',18))#直接在花括号写明赋值给谁
# print('my name is {x} my age is {y}'.format(y=18,x='egon'))
##find,rfind,index,rindex,count
# msg='hello world'
# # print(msg.find('h'))#从左往右依次查找,如果有,则返回第一个字符的索引
# # print(msg.find('hahah'))#如果找不到,则返回-1
# # print(msg.index('1'))#查不到字符直接报错
# print(msg.count('l',0,4))#从1-4查找字符l,顾头不顾尾
#.split,join
# msg='root:x:00:hahah'
# print(msg.split(':'))#split以:切分
# print(':'.join(msg.split(':')))#join以:还原
#center,ljust,rjust,zerofile
# print('haha'.center(10,'@'))#以10的宽度,@符号作为填充,使haha居中
# print('haha'.ljust(10,'@'))#填充右边
# print('haha'.rjust(10,'@'))#填充左边
# print('haha'.zfill(30))#用0填充,30的宽度
#is系列
#name='alex'
# print(name.isupper())#全部是大写
# print(name.islower())#全部是小写
# print(name.istitle())#首字母大写
# name='abc123'
# print(name.isalnum())#字符串是字母和数字组成
# print(name.isalpha())#由字母组成
#判断数字
# age=10
# inp=input('请输入年龄:')#
# if inp.isdigit():#判断字符串类型包含的字符是否是纯数字
# inp=int(inp)
# if inp>age:
# print('ok')
# else:
# print('必须输入数字')
# num1=b'4' #bytes
# num2=u'4' #unicode,python3中无需加u就是unicode
# num3='四' #中文数字
# num4='壹' #中文繁体
# num5='Ⅳ' #罗马数字
# print(num1.isdigit())#只能判断bytes,unicode
# print(num2.isdecimal())#只能判断unicode
# print(num2.isnumeric())#能判断2、3、4、5
#print(name.isspace())#是否为空格
#print(name.isidentifier())#用来判断字符内包含不包含Python的关键字
列表类型
#作用:多个装备,多个爱好,多门课程,多个女朋友等
#定义:[]内可以有多个任意类型的值,逗号分隔
# my_girl_friends=['alex','wupeiqi','yuanhao',4,5] #本质my_girl_friends=list([...])
#优先掌握的操作:
# 按索引存取值(正向存取+反向存取):即可存也可以取
# print(my_girl_friends[2])#正向取
# print(my_girl_friends[-1])#反向取
# my_girl_friends[0]='xiaohong'
# print(id(my_girl_friends))
# print(my_girl_friends)
# 切片(顾头不顾尾,步长)
# print(my_girl_friends[0:2])
# print(my_girl_friends[0:4:2])
# 长度
# print(len(my_girl_friends))
# 成员运算in和not in
# print('alex' in my_girl_friends)
# 追加
# my_girl_friends.append('xiaoming')
# print(my_girl_friends)
# 删除
# del my_girl_friends[2]
# print(my_girl_friends)
#print(my_girl_friends.remove('alex'))#remove是单纯的删除,不会返回删除的值,而且是按照值取删
# my_girl_friends.pop()#按照索引删,默认删除最后一个
# print(my_girl_friends)
# 循环
#常用操作
# my_girl_friends=['alex','wupeiqi','yuanhao',4,5,4]
# my_girl_friends.insert(0,'xiaohong')#插入值
# my_girl_friends.extend([1,2,3])#以列表的形式把多个值添加到列表最后面
#print(my_girl_friends.count(4))#查看有几个相同字符
#my_girl_friends.clear()#清空列表
#print(my_girl_friends)
# l=my_girl_friends.copy()
# print(l)
# my_girl_friends.reverse()#单纯的反转列表里的值
# print(my_girl_friends)
# l=[1,2,3,-1,-3,5]#把无序的列表数据排列有序
# l.sort(reverse=True)#加上reverse=True后,数字顺序从大到小,不加从小到大
# print(l)
#元组类型
#可以存多个值,有序,但是元组不可改
#作用:存多个值,对比列表来说,元组不可变(是可以当做字典的key的),主要是用来读
#定义:与列表类型比,只不过[]换成()
# age=(11,22,33,44,55)本质age=tuple((11,22,33,44,55))
# #优先掌握的操作:
# 按索引取值(正向取+反向取):只能取
# name=('xiaohong','xiaoming','3号','4号')
# print(name[2])
# # 切片(顾头不顾尾,步长)
# print(name[0:2])#只是切出一个新的列表,原来的列表并没有变化
# # 长度
# print(len(name))
# # 成员运算in和not in
# print('xiaoming' in name)
# 循环
#其他操作
#index
# print(name.index('xiaohong'))
# print(name.index('xiaobai'))
#count
# print(name.count('xiaoming'))
# l=['a','b','c','d','e']
# l1=('a','b','c','d','e')
# l2='abcde'
# # index=0
# # while index<len(l):
# # print(l[index])
# # index+=1
# for ha in l2:
# print(ha)
# for i in range(1,101,2):#取1-101间的奇数
# print(i)
#间接用for循环按照索引取值
# l=['a','b','c','d','e']
# for i in range(len(l)):
# print(i,l[i])
# pythons=['alex','wupeiqi','egon','yuanhao','gangdan','oldboy']
# linuxs=['egon','oldboy','tiedan','liudan']
#
# l=[]
# for item in pythons:
# if item in linuxs:
# l.append(item)
# print(l)
# 作用:去重,关系运算,
# 定义:
# 1:每个元素必须是不可变类型(可hash,可作为字典的key)
# 2:没有重复的元素
# 3:无序
# s={1,2,'a','b','c','d','e','f'} #s=set({1,2,'a'})
# print(type(s),s)
# 优先掌握的操作:
# 长度len
# s={1,2,'a','b','c','d','e','f'}
# print(len(s))
# 成员运算in和not in
# print('a' in s)
# for item in s:
# print(item)
# | 并集
# s1={1,2,3}
# s2={3,4,5}
# print(s1 | s2)
# & 交集
# print(s1 & s2)
# -差集
# print(s1 - s2)
# print(s2 - s1)
# ^ 对称差集
# s1={1,2,3}
# s2={3,4,5}
# ==
# > , >= , <, <= 父集,子集
# s1={1,2,3,4}
# s2={3,4,5}
# print(len(s1) > len(s2))
# s1={1,2,3,4}
# s2={3,4}
# print(s1 > s2)#s1是否包含s2,包含就是>
# print(s1 >= s2)
# 常用操作
# s1 = {1, 2, 3, 'a', 4}
# print(s1.pop()) #随机删,并返回删除的结果
# s1.remove('a') #单纯地删,不会返回删除的结果,并且如果删除的元素不存在则报错
# s1.remove('asdfasdfa') #单纯地删,不会返回删除的结果
# print(s1)
# print(s1.discard('a')) #单纯地删,不会返回删除的结果,并且如果删除的元素不存在返回None,不会报错
# print(s1)
# s1.add('b')
# print(s1)
# s1 = {1, 2, 3}
# s2 = {4, 5}
# print(s1.isdisjoint(s2)) #如果s1和s2没有交集则返回True
# 了解
# s1={1,2,3,4}
# s2={3,4,5}
# | 并集
# print(s1.union(s2))
# & 交集
# print(s1.intersection(s2))
# s1.intersection_update(s2) #s1=s1.intersection(s2)
# print(s1)
# -差集
# print(s1.difference(s2))
# ^ 对称差集
# print(s1.symmetric_difference(s2))
# ==
# > , >= , <, <= 父集,子集
# s1={1,2,3,4}
# s2={3,4}
# print(s1.issuperset(s2))
# print(s2.issubset(s1))
# 去重
# l=['a','b',1,'a','a']
# print(list(set(l)))
# l=['a','b',1,'a','a']
# l_new=list()
# s=set()
# for item in l:
# if item not in s:
# s.add(item)
# l_new.append(item)
# l = [
# {'name': 'egon', 'age': 18, 'sex': 'male'},
# {'name': 'alex', 'age': 73, 'sex': 'male'},
# {'name': 'egon', 'age': 20, 'sex': 'female'},
# {'name': 'egon', 'age': 18, 'sex': 'male'},
# {'name': 'egon', 'age': 18, 'sex': 'male'},
# ]
# l_new = list()
# s = set()
# for item in l:
# res = (item['name'], item['age'], item['sex'])
# if res not in s:
# s.add(res)
# l_new.append(item)
#
# print(l_new)
#
# # 了解:不可变集合
# fset = frozenset({1, 2, 3})