# 1、按照索引取值
# name = 'hello world'
# print(name[0]) # 按照索引取值
# 2、切片
# print(name[1:4]) # 切片取值 顾头不顾尾
# print(name[-1:-4:-1]) # 默认从左往右 -1表示从右往左
# print(name[1:4:2]) # 第三个数表示步长
# 3、长度len
# print(len(name)) # len 统计字符串里的个数
# 4、成员运算in和not in
# print('hello' in name) # in 判断...在...里面
# print('hello' not in name) # not in 判断...不在...里面
# 5、移除指定的首尾字符strip
# username = input('username>>:')
# username = username.strip() # strip() 移除指定的首位字符
# 例:移除首位空格
# username = input('username>>:').strip()
# if username == 'sodo':
# print('登陆成功')
# else:
# print('登陆失败')
# 例:移除指定首尾字符
# username1 = '$$so$$do'
# username2 = ' sodo '
# print(username1.strip('$')) # 默认移除首尾所有字符
# print(username2.strip()) # 默认移除首尾所有空格
# n1 = '$$sodo$$'
# print(n1.lstrip('$')) # 移除首位指定字符
# print(n1.rstrip('$')) # 移除尾部指定字符
# 6、切分split
# res = 'sodo|123|read'
# print(res.split('|')) # 指定切割的字符不保留 切割后是一个列表
# print(res.split('|', maxsplit=1)) # 从左往右切割的次数
# print(res.rsplit('|', maxsplit=1)) # 从右往左切割
# 7、循环
# name = 'sodo'
# for i in name:
# print(i) # 依次获取字符串中单个单个的字符
# 8、转换输出类型
# print(type(str(True))) # 将bool型True转换成字符串类型
# 9、字母转换大小写
# res = 'My NAME is SoDO'
# print(res.upper()) # 将所有字母转换成大写
# print(res.lower()) # 将所有字母转换成小写
# print(res.isupper()) # 判断字符串内所有字母是否全是大写
# print(res.islower()) # 判断字符串内所有字母是否全是小写
# print(res.title()) # 将所有字母单词首字母大写
# print(res.capitalize()) # 首字母大写 后面统一变小写
# 例
# code = 'SodO666'
# my_code = input('code>>>:')
# if code.upper() == my_code.upper(): # 把code和my_code全部转换成大写判断
# print('输入正确')
# 9、判断字符串是否以...开头/结尾
# res = 'my name is sodo'
# print(res.startswith('my')) # 判断字符串是否以my开头
# print(res.endswith('sodo')) # 判断字符串是否以sodo结尾
# 10、字符串格式化输出
# %s %d format
# res = 'my name is {} my age is {}'
# print(res.format('sodo',18)) # 按照个数位置一一传值
# res = 'my name is {1} my age is {0}'
# print(res.format('sodo',18)) # 按照索引取值
# res = 'my name is {name} my age is {age}'
# print(res.format(name='sodo', age=18)) # 指名道姓取值
# 11、统计字符串中,指定字符出现的次数
# res = 'my name is sodo'
# print(res.count('o')) # 判断字符串中o出现的次数
# print(res.count('m', 0, 2)) # 指定判断0-2个字符中m出现的次数
# 统计列表中某个元素出现的字数
# l1 = [11, 22, 33, 44, 55, 11, 22, 55]
# print(l1.count(11))
# 清空列表
# l1.clear()
# print(l1)
# 12、判断非数字 特殊符号
# res = 'sodo苏打-'
# print(res.isalpha())
#flash
# 13、判断是否纯数字
# age = input('请输入你的年龄>>:')
# if age.isdigit(): # 判断输入的是否为纯数字
# age = int(age) # 将输入的字符串数字转换为整型的数字
# else:
# print('请输入纯数字')
# 14、替换
# res = 'my name is sodo sodo sodo'
# print(res.replace('sodo', 'yyds')) # 将所有的sodo替换成yyds
# print(res.replace('sodo', 'yyds', 1)) # 将第一个sodo替换成yyds
# 15、将列表多个元素拼接成字符串
# res = ['sodo', 'yyds', 'awsl']
# print(','.join(res)) # 将列表多个元素拼接成字符串
# 只能是字符串类型才能一起拼接
# 16、列表元素的增删改查(CURD)
# name = ['sodo', 'yyds']
# name.append('awsl') # 末尾增加单个元素
# print(name)
# name.insert(0,'awsl') # 指定位置插入
# print(name)
# l1 = [11, 22, 33, 44, 55, 66]
# for i in l1: # 依次从l1中取值到i
# name.append(i) # 将取到的值插入到name中
# name.extend(l1) # 等同于上面for+append的代码
# print(name)
# 17、通用的删除操作
name = ['sodo', 'yyds']
# del name # 解除name与索引的关系
# print(name)
# res = name.remove('yyds') # 指名道姓删除
# print(name)
# print(res)
# res1 = name.pop() # 默认弹出尾部元素
# print(name)
# print(res1) # 弹出了哪个
# res3 = name.pop(0) # 指定弹出位置的元素
# print(name)
# print(res3)
# 18、排序
# l1 = [1, 3, 8, 2, 6, 2]
# l1.sort() # 默认是升序
# print(l1)
#
# l1.sort(reverse=True) # 降序 reverse=True
# print(l1)
# l1.reverse() # 倒序
# print(l1)
# 可变不可变
# 可变类型
# 值改变 内存地址不变
# l1 = [11, 12]
# print(id(l1))
# l1.append(666)
# print(id(l1))
# 不可变类型
# 值改变 内存地址一定变
# a = 1
# print(id(a))
# a = 2
# print(id(a))