print({10,20,30} =={30,10,20})
#True
s1 =set()
print(type(s1),len(s1)) #set
s2 = {10,2.3,True,(10,20),'abc'}
print(s2)
#{True, 2.3, 10, 'abc', (10, 20)}
s3 = {10,20,30,10,10}
print(s3)
#{10, 20, 30}
s1 = {10,89,21,2023,7}
s1.add(100)
print(s1)
s1 = {10,89,21,2023,7}
s1.remove(10)
print(s1)
s1 = {10,89,21,2023,7}
s1.discard(10)
print(s1)
s1 = {1,2,3,4,5,6,7}
s2 = {5,6,7,8,9,10}
print(s1 & s2)
# 5 6 7
s1 = {1,2,3,4,5,6,7}
s2 = {5,6,7,8,9,10}
print(s1 | s2)
#{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
s1 = {1,2,3,4,5,6,7}
s2 = {5,6,7,8,9,10}
print(s1 - s2)
#{1, 2, 3, 4}
s1 = {1,2,3,4,5,6,7}
s2 = {5,6,7,8,9,10}
print(s1 ^ s2)
#{1, 2, 3, 4, 8, 9, 10}
python = {'stu1', 'stu3', 'stu4','stu5'}
java = {'stu2', 'stu3', 'stu4'}
h5 = {'stu2', 'stu4','stu6'}
# 1)求选课学生总人数
print(python | java | h5 )
# 2)求同时选三门学科的学生有哪些
print(python & java & h5)
# 3)只选了python有哪些
print(python-(java | h5))
# 4)只选了一门学科的学生有哪些
print((python - java - h5) | (java - python - h5) | (h5 - python - java))
# 5)同时选了两门学科的学生有哪些
print((python & java) | (python & h5) | (java & h5))
区别:
print({100,200,300} > {100,200}) #True
#判断 {100,200} 是否是{100,200,300}的真子集
str1 = 'abc\n123'
print(str1)
#abc
#123
poem = 'it\'s me'
print(poem)
#it's me
path = 'c:\\name\\test\\demo.txt'
print(path)
c:\name\test\demo.txt
path = r'c:\name\test\demo.txt'
print(path)
print(chr(97)) # a
print(chr(65))# A
for i in range(65,65+26):
print(chr(i)) # 从A ~ Z
# 16进制前必须加 0x
for i in range(0x4e00,0x9fa5):
print(chr(i),end='') #中文生僻字
print(ord('姚'),ord('欣'))
#23002 27427
x = 'm'
print(chr(ord(x)-32))
print('\u4e00') # 一
print('一‘)#一
案例: 判断x保存的字符是否是中文字符
x = '姚'
print('\u4e00' <=x <= '\u9f5a') #中文编码表范围
#True
print('hello' + 'python')
应用场景:利用字符串 的 + 和空串 ' ', 可以实现对字符串的增删改
1:删除str1中所有的中文字符
for i in str1:
if '\u4e00' <= i <= '\u9fa5':
continue
empty += i
print(empty)
2:将str1中所有的中文字符替换成+
empty1 = ''
str1 = 'ms吗n23KS=-模式2.ksKAHss,s'
for char in str1:
if '\u4e00' <= char <= '\u9fa5':
### 如果是中文就拼 +
empty1 += '+'
else:
### 如果不是中文就 拼 这个字符
empty1 += char
print(empty1)
## 是否为中文
'\u4e00' <= x <= '\u9f5a'
#是否为小写字母
'a' <= x <= 'z'
#是否为大写字母
'A' <= X <= 'Z'
#是否为字母
'a' <= x <= 'z' or 'A' <= X <= 'Z'
# 是否为数字字符
'0' <= x <= '9'