#String 操作
# a="Let's go "
# print(a)
# 1 * 重复输出字符串
# print('hello'*20)
# 2 [] ,[:] 通过索引获取字符串中字符,这里和列表的切片操作是相同的,具体内容见列表
# print('helloworld'[2:])
#关键字 in
# print(123 in [23,45,123])
# print('e2l' in 'hello')
# 4 % 格式字符串
# print('alex is a good teacher')
# print('%s is a good teacher'%'alex')
#5字符连接
# a='123'
# b='abc'
# d='44'
# # # c=a+b
# # # print(c)
# #
# c= ''.join([a,b,d])
# print(c)
# String的内置方法
# st='hello kitty {name} is {age}'
#
- # print(st.count('l')) # 统计元素个数
- # print(st.capitalize()) # 首字母大写
- # print(st.center(50,'#')) # 居中
- # print(st.endswith('tty3')) # 判断是否以某个内容结尾
- # print(st.startswith('he')) # 判断是否以某个内容开头
- # print(st.expandtabs(tabsize=20))#设定tab键的空格
- # print(st.find('t')) # 查找到第一个元素,并将索引值返回,查询不到不会报错
- # print(st.format(name='alex',age=37)) # 格式化输出的另一种方式 待定:?:{}
- # print(st.format_map({'name':'alex','age':22}))#格式化输出
- # print(st.index('t'))#查询t字符,如果查询不到就报错
- # print('asd'.isalnum())#判断是不是包含数字和字母和汉字。特殊字符不行
- # print('12632178'.isdecimal())#判断是否是十进制的数
- # print('1269999.uuuu'.isnumeric())#判断是不是数字
- # print('1269999.uuuu'.isdigit())#判断是否是个整数字。浮点数不行
- # print('abc'.isidentifier())#判断是否非法字符,例如变量名
- # print('Abc'.islower())#判断是不是小写,全小写
- # print('ABC'.isupper())#判断是不是全大写
- # print(' e'.isspace())#判断是不是空格
- # print('My title'.istitle())#判断标题,每个单词的首字母大写
- # print('My tLtle'.lower())#转小写
- # print('My tLtle'.upper())#转大写
- # print('My tLtle'.swapcase())#大写转小写,小写转大写
- # print('My tLtle'.ljust(50,'*'))#靠左字符*补充在右边填充到50个
- # print('My tLtle'.rjust(50,'*'))#靠右
- # print('\tMy tLtle\n'.strip())#把左右的换行符和空格去掉
- # print('\tMy tLtle\n'.lstrip())#去除左边
- # print('\tMy tLtle\n'.rstrip())#去除右边
- # print('ok')
- # print('My title title'.replace('itle','lesson',1))#替换(替换的对象,替换的内容,替换的次数)不加次数则全部替换
- # print('My title title'.rfind('t'))#从右边开始寻找
- # print('My title title'.split(' '))#以空格作为分割,然后存进列表["My","title","title"]
- # print('My title title'.rsplit('i',1))#只分割1次,以右为准
- # print('My title title'.split('i',1))#只分割1次
- # print('My title title'.title())#首字母大写
- #摘一些重要的字符串方法
- #1 print(st.count('l'))
- # print(st.center(50,'#')) # 居中
- # print(st.startswith('he')) # 判断是否以某个内容开头
- # print(st.find('t'))
- # print(st.format(name='alex',age=37)) # 格式化输出的另一种方式 待定:?:{}
- # print('My tLtle'.lower())
- # print('My tLtle'.upper())
- # print('\tMy tLtle\n'.strip())
- # print('My title title'.replace('itle','lesson',1))
- # print('My title title'.split('i',1))