#! /usr/bin/nev python3
# -*- Coding: UTF-8 -*-
# str.py
# @作者 lgq
# @创建日期 2020-10-25T04:36:05.616Z+08:00
# @最后修改日期 2020-10-25T04:36:05.616Z+08:00
#
# 字符串
# str
# test = 'alex'
# v = test.capitalize() #首字母大写
# print(v)
# text1 = "aLex"
# v1 = text1.casefold() # 所有变小写,很多未知的对相应变小写
# print(v1)
# v2 = text1.lower() # 变小写
# print(v2)
# 填充占位 默认空白填充 字符居中 ljust字符串居左 rjust 字符串居右
# v = test.center(20)
# v = test.center(20,"-")
# v = test.ljust(20,'*')
# v = test.rjust(20,'*')
# 查询子序列出现的次数,可定义起始位置和结束位置
# text = "vfdavfbd"
# v = text.count('vf')
# v = text.count('vf',5,7)
# print(v)
# encode
# decode
# 判断是否以子序列结尾或开始 , 客定义起始位和结束位
# test = "alex"
# v = test.endswith('e', 1, 3)
# v1 = test.startswith("l")
# print(v)
# print(v1)
# 把字符串中的 tab 符号 \t 转为空格,tab 符号 \t 默认的空格数是 8
# 6 个空格
# 132456789 有 9 个字符,刚好是 2 的 3 倍,后面的 \t 填充 2 个空格
# 12345 有 5 个字符,不是 2 的倍数,后面的 \t 填充 1 个空格
# text = "132456789\t123"
# v = text.expandtabs(2)
# print(v, len(v))
# 查询子序列从前往后查找第一次出现的位置,可定义起始位和结束位 find 未找到 返回 -1 index未找到 报错
# test = "vfdavfa"
# v = test.find("d")
# 格式化 ,将字符串汇总的占为符替换制定的值
# test = 'i am {name} , age {a}'
# v = test.format(name='alex', a=19)
# # i am alex , age 19
# print(v)
# test = "I am {0} , age {1}"
# v = test.format('alex', 19)
# print(v)
# test = 'i am {name} , age {a}'
# v = test.format_map({'name': "alex", 'a': 19})
# print(v)
# 字符串中只允许出现字母和数字 返回 bool值
# test = "cdv48cs"
# v = test.isalnum()
# print(v)
# 字符串中只允许出现字母和汉字 返回 bool值
# test = 'vfavf户vf'
# v = test.isalpha()
# print(v)
# 判断是否是数字 isdigit可判断特殊数字 isnumeric可判断中文
# test = '123456'
# v = test.isdecimal()
# v1 = test.isdigit()
# v3 = test.isnumeric()
# print(v, v1,v3)
# 检查字符串是否为有效标识符
# test = 'def\t_156'
# v2 = test.isidentifier()
# print(v2)
# 判断是否是小写
# v = test.islower()
# print(v)
# 判断是否包含不可见的字符
# v = test.isprintable()
# print(v)
# 判断是否全部是空格
# test = ' '
# v = test.isspace()
# print(v)
# 判断是否是标题 以及变成标题
# test = 'bvfdvf vfda fdafd fd sc'
# v1 = test.istitle()
# print(v1)
# v2 = test.title()
# print(v2)
# 将字符串中的每一个元素按照指定分隔符进行拼接
# test = '及vfdialafv'
# t = '\\'
# v = t.join(test)
# print(v)
# 转换小写
# test = 'Alex'
# v1 = test.lower()
# # 判断小写
# v2 = test.islower()
# # 转换大写
# v3 = test.upper()
# # 判断大写
# v4 = test.isupper()
# # 去除空白和指定字符 lstrip rstrip
# v5 = test.strip()
# 替换指定字符
# test = 'qwert'
# test1 = '12345'
# m = str.maketrans(test, test1)
# v = 'dsfewerbrwbt'
# new_v = v.translate(m)
# print(new_v)
# 将字符串进行分割 ('rtedfda', 's', 'rfsfbffes')
# test = 'rtedfdasrfsfbffes'
# v = test.partition('s') # 分割包含s
# v = test.rpartition('s') # ('rtedfdasrfsfbffe', 's', '')
# print(v)
# v = test.split('s', 2) # 分割不包含s
# print(v)
# v1 = test.rsplit('s')
# 分割 ,只能根据True ,Fales ,是否保留换行
# test = 'vfdsgsgrs\nreagvvsgref\nfrearea'
# v = test.splitlines(False)
# print(v)
# 判断是否以指定字节开头
# test = 'vfdvsnr189.vf'
# # v = test.startswith('f')
# # print(v)
# # 判断是否以指定字节结尾
# v =test.endswith('f')
# 大小写转换
# test = "decdsv"
# v = test.swapcase()
# print(v)
# 判断是否包含特殊字符 没有返回true
# v = test.isidentifier()
# print(v)
# test = 'alex'
# test1 = 'ulex'
# 索引 ,下标 获取字符串中某一个字符
# v1 = test[3]
# print(v1)
# 索引范围 切片
# v2 = test[0:-1]
# print(v2)
# test3 = '你好阿'
# 获取当前字符串中有几个字符组成
# v = len(test3)
# print(v)
# test = '我去尼斯的第三方地方'
# index = 0
# while index < len(test):
# v = test[index]
# print(v)
# index += 1
# for 循环
# for saf in test:
# print(saf)
# 替换字符串中指定字符 可指定替换相同字符 的个数
# test = 'aliesxfvfd'
# v = test.replace('es', 'bababa')
# print(v)
# li = '个百分点'
# for item in li:
# # continue # 跳过当前循环
# print(item)
# break # 终止循环
# v = range(1, 100, 5)
# print(v)
# for item in v:
# print(item)
# test = input(">>>")
# l = len(test)
# r = range(0, l)
# for irem in r:
# print(irem, test[irem])