# 1、作用

# 2、定义
mse = 'python'
print(type(mse))
# 3、类型转换
mesg = str({'a': 1})
print(mesg, type(mesg))
# 4、使用:内置方法
# 优先掌握的操作:
# 4.1、按索引取值(正向取+反向取) :只能取(字符串为不可变类型)
x = 'hello '
# 正向取
print(x[0])

# 反向取
print(x[-1])
# 只能取

# 4.2、切片(顾头不顾尾,步长)
x = 'hello '
res = x[0:3]
print(res)
print(x)
# 步长
res = x[0:3:2]
print(res)
# 反向步长
res = x[-1:0:-1]
print(res)
y = 'hello world!'
ros = y[:]  # 默认为 0 到末尾
print(ros)
ras = y[::-1]  # 倒着取
print(ras)
# 4.3、长度len
print(len(x))

# 4.4、成员运算in和not in
a = 'loky leran python!'
print('loky' in a)
print('loky' not in a)  #
print(not 'loky' in a)  # 不推荐
# 4.5、移除空白strip 移除左右两侧的符号

msg = '           loky       '
res = msg.strip()  # 默认去掉的空格

print(msg)  # 不会改变原值

print(res)  # 产生新值
v = '$$$$$$$$$$$$$loky$$$$$$$$$$'
print(v.strip('$'))
s = '$$$$$$lo$$$$$$ky$$$$$$$$$$'
print(s.strip('$'))  # 只能去除两边的

# in_user = input('请输入账号:').strip()
# in_pwd = input('请输入密码:').strip()
# if in_user == 'loky' and in_pwd == '123':
#     print('login successful!')
# else:
#     print('sorry,fail to login!')
# 4.6、切分split:把一个字符串按照某种分隔符进行切分,得到一个列表

info = 'loyk lss ok'
res = info.split()
print(res) #不写默认空格!
info = 'loyk:lss:ok'
res = info.split(':')
print(res) #分隔符:!
#切分次数|(了解就好)
info = 'loyk:lss:ok'
res = info.split(':',1)#分隔1次!
print(res) #
# 4.7、循环

for i in 'loky is so handsome!':
    print(i)


# 5、优先级掌握

# 需要掌握

#5.1、strip,lstrip,rstrip
v = '$$$$$$$$$$$$$loky$$$$$$$$$$'
print(v.strip('$'))
print(v.lstrip('$')) #左去除
print(v.rstrip('$'))#右去除
#5.2、lower,upper
c ='AAAAggggSSSSS'
print(c.lower())#全改为小写
print(c.upper())#全改为大写
#5.3、startswith,endswith
c ='loky is handsome'
print(c.startswith('loky'))
print(c.endswith('handsome'))
#5.4、format的三种玩法
#5.5、split,rsplit
info = 'loky:18:male'
print(info.split(':',1))
print(info.rsplit(':',1))
#5.6、join  :把列表拼接成字符串
l =['loky','18','handsosme']
#法一:
# res = l[0]+l[1]+l[2]
# print(res)

#法二:
res = ':'.join(l)#按照某个分隔符符号,把元素全为字符串的列表拼接成一个大字符串
#注意,列表内只能是字符串与字符串相加1
print(res)
#5.7、replace
msg = 'hello world python'
res=msg.replace('hello','nihao')
print(res)
#5.8、isdigit
#判断字符串是否为字符串组成!
mes = '1123123'
print(mes.isdigit())


# age =input('亲输入年龄猜测:').strip()
#
# if age.isdigit():
#     age = int(age)
#     if age  >18:
#         print('猜测大了!')
#     elif age<18:
#         print('猜测小了!')
#     else:
#         print('猜对了!')
# else:
#     print('输入有错!只能输入数字谢谢!')

# 6、了解
#6.1、find,rfind,index,rindex,count
msg = 'hello world'
print(msg.find('e')) #找到返回1 ,找不到返回-1
#index
# print(msg.index('dddddd'))       找不到就报错
print(msg.count('hello'))
#6.2、center,ljust,rjust,zfill
print('loky'.center(20,'&'))
print('loky'.ljust(20,'&'))
print('loky'.rjust(20,'&'))
print('loky'.zfill(20))#默认右对齐,无法改变!
#6.3、expandtabs
msg = 'hello\tpython!'
print(msg)
print(msg.expandtabs(2)) #设置空格数为二

#6.4、captalize,swapcase,title
print('HHHHelllOOOO'.capitalize())#大写转小写,首字母转大写
print('HHHHelllOOOO'.swapcase())#大写转小写,小写转大写
print('HHHHelllOOOO'.title()) #就只是首个字母为大写
# Hhhhellloooo
# hhhhELLLoooo
# Hhhhellloooo
#6.5、is数字系列
#在python3中
num1=b'4' #bytes
num2=u'4' #unicode,python3中无需加u就是unicode
num3='四' #中文数字
num4='Ⅳ' #罗马数字
num5='肆' #旧版数字

#isdigt:bytes,unicode
print(num1.isdigit()) #True
print(num2.isdigit()) #True
print(num3.isdigit()) #False
print(num4.isdigit(),'测试') #False
print(num5.isdigit())#False

#isdecimal:uncicode
#bytes类型无isdecimal方法
print(num2.isdecimal()) #True
print(num3.isdecimal()) #False
print(num4.isdecimal()) #False

#isnumberic:unicode,中文数字,罗马数字
#bytes类型无isnumberic方法
print(num2.isnumeric()) #True
print(num3.isnumeric()) #True
print(num4.isnumeric()) #True
print(num5.isnumeric(),'测试') #True
#三者不能判断浮点数
print(num5.isdigit())
print(num5.isdecimal())
print(num5.isnumeric())
'''
总结:
    最常用的是isdigit,可以判断bytes和unicode类型,这也是最常见的数字应用场景
    如果要判断中文数字或罗马数字,则需要用到isnumeric
'''


#6.6、is其他
print('===>')
name='loky123'
print(name.isalnum()) #字符串由字母或数字组成
print(name.isalpha()) #字符串只由字母组成

print(name.isidentifier())
print(name.islower()) #字符串中字母是否全为小写
print(name.isupper())#字符串中字母全为大写
print(name.isspace())#字符串中是否全为空格
print(name.istitle())#字符串中是否为首字母是否为大写