#1、作用
#2、定义
msg='hello' #msg=str('msg')
#类型转换
#str可以把任意其他类型都装成字符串了
# res=str({'a':1})
# print(res,type(res))
#4、使用:内置方法
#4.1有限掌握
#4.1.1 按索引值(正向取+反向取):只能取
# msg='hello world'
#z正向取
# print(msg[0])
#反向取
# print(msg[-1])
#只能取
# msg[0]='H' #报错,不能改,只能取
#4.1.2 切片(只顾头不顾尾,步长),索引的拓展应用,从一个大的字符串中拷贝出一个子字符串
# print(msg[0:5]) #hello
#步长
# print(msg[0:5:2]) #0 2 4这三个位置的字符取出来 hlo
#反向步长
# res=msg[5:0:-1] #起始位置是5 终止位置是0 ,5取得到,0取不到,从5开始到0,倒着走
# print(res) #olle
#一般用在
# msg='hello world'
# res=msg[:] #res=msg[0:11] #完整拷贝
# print(res)
# res=msg[11::-1] #整个字符串倒过来
# print(res)
#4.1.3 长度(len)
# print(len(msg))
#成员运算in和 not in
#判断一个子字符串是否存在于一个大字符串中
# print('alex' in 'alex is sb')
# print('alex' not in 'alex is sb')
#5、移除字符串左右两侧的符号 空白strip
# msg=' egon '
# res=msg.strip() # #不会改变原值
# print(msg)
# print(res) #d打印:msg
# msg='*****egon******'
# res=msg.strip('*')
# print(res)
#strip只去两边不去中间
# msg='*****e***gon****'
# print(msg.strip('*')) #输出:e***gon
# msg='**/*=-**egon**-=()**'
# print(msg.strip('*/-=()')) #egon
#应用
# in_user=input('your name:').strip()
# in_pwdr=input('your password>>:').strip()
# if in_user == 'egon' and in_pwdr == '123':
# print('登录成功')
# else:
# print('登录失败')
#6 、切分split:吧一个字符串按照某种分隔符进行切分,得到的、一个列表
# info='egon 18 male' #默认的分隔符是空格
# res=info.split()
# print(res) #['egon', '18', 'male']
#指定分隔符
# info='egon:18:male' #默认的分隔符是空格
# res=info.split(':')
# print(res) #['egon', '18', 'male']
#指定分割次数
# info='egon:18:male' #默认的分隔符是空格
# res=info.split(':',1)
# print(res) #['egon', '18:male']
#4.1.7 x循环
# info='egon:18:male'
# for x in info:
# print(x)
#4.2 需要掌握的操作
#4.2.1 strip,lstrip,rstrip
# msg='**********egon**********'
# print(msg.strip('*'))
# print(msg.lstrip('*')) #只去左边
# print(msg.rstrip('*')) #只去右边
#4.2.2 lower,upper
# msg='AAAAbbbACCCc'
# print(msg.lower())
# print(msg.upper())
#4.2.3 startswitch,endswith
# print('alex is sb'.startswith('alex'))
# print('alex is sb'.endswith('sb'))
#4.2.4 format的三种玩法
#4.2.5 split,resplit :将字符串切成列表
# info='enon:18:male'
# print(info.split(':',1)) #['enon','18:male']
# print(info.rsplit(':',1)) #['enon:18','male']
#4.2.6 join:吧列表拼接成字符串
# l=['egon','18','male']
# res=l[0]+l[1]+l[2]
# print(res)
# res=':'.join(l) #按照某个分隔符,吧元素全为字符串的列表拼接成大字符串
# print(res) #egon:18:male
#4.2.7 replace
# msg='you can you up ,no can no bb'
# res=msg.replace('you','YOU',1) #第三个元素是指定修改元素位置,
# # 不加则是默认修改自字符串中所有的you,加了就是指定位置的修改
# print(res)
#4.2.8 isdigit
#判断字符串是否由纯数字组成
# print('123'.isdigit())
# age=input('请输入你的年龄:').strip()
# if age.isdigit():
# age=int(age) #int('aaabb')
# if age > 18:
# print('猜大了')
# elif age < 18:
# print('小了')
# else:
# print('对了!')
# else:
# print('请输入数字:')
#4.3 了解
#4.3.1 find,refind,index,ridex,count
# msg='hello egon hahaha'
# res=msg.find('e') #返回要查找的字符串在大字符串中的起始索引 结果为 1
# print(msg.find('egon')) #返回6,返回-1代表找不到
# print(res)
# #区别在于找不到,find返回 -1, index 抛出异常
# print(msg.index('egon')) #6
#4.3.2 center,ljust,rjust,zfill
# msg='hello egon hahaha egon、egon'
# print(msg.count('egon'))
# print('egon'.center(50,'*'))
# print('egon'.ljust(50,'*'))
# print('egon'.rjust(50,'*'))
# print('egon'.zfill(10))
'''
3
***********************egon***********************
egon**********************************************
**********************************************egon
000000egon
'''
#4.3.3 expandtabs
# msg='hello\tworld' #设定制表符代表的空格为2
# print(msg.expandtabs(2)) #hello world
#4.3.4 capalize,swpacase ,title
# print('hello world'.capitalize()) #首字母大写
# print('helLo World'.swapcase()) #大小写转换
# print('helLo World'.swapcase()) #大小写转换
# print('hello world egon'.title()) #单词搜字母大写
'''
# hello world
# Hello world
# HELlO wORLD
# HELlO wORLD
# Hello World Egon
'''
#is 数字类型
# print('abc'.islower())#判断字符串是否全为小写
# print('ABC'.isupper()) #判断字符串是否全为大写
# print('Hello World'.istitle()) #判断单词首字母为大写
# print('123abc'.isalnum())#判断字符串是否全为大写 #字母或数字或者纯数字组成
# print('abc'.isalpha()) #判断字符串是否全为字母
# print(' '.isspace()) #判断字符串是否全为空格
# print('if'.isidentifier()) #判断python是否是内置或者是自定义的名字
#结果全为true
# is 其他
num1=b'4' #bytes
num2=u'4'#unicode,python3中无需加就是unicod
num3='四' #中文数字
num4='Ⅳ' #罗马数字
#isdigit 只能识别num1,num2
# print(num1.isdigit()) #true
# print(num2.isdigit()) #True
# print(num3.isdigit()) #False
# print(num4.isdigit()) #False
#isnumberic 以下全为True,num2,num3,num4
# print(num2.isnumeric())
# print(num3.isnumeric())
# print(num4.isnumeric())
#isdecimal
print(num2.isdecimal()) #true
print(num3.isdecimal()) #false
print(num4.isdecimal()) #false
#7、循环