#一、字符串的魔法
# 1、num = 9 / 2
# print(num) //num=4.5
# 2、num = 9 // 2
# print(num) //num=4
# 3、name = "william"
# if "il" in name:
# print("OK")
# else:
# print("Error") //OK
# 4、v = 1 == 2
# print(v) //False
# 5、upper把小写字母转为大写
# num = "abcdefg"
# v = num.upper()
# print(v) //ABCDEFG
#num = "LaiYing"
# v = num.upper()
# print(v) //LAIYING
#6、bit_length 输出字符二进制长度
# a = 5
# len = a.bit_length()
# print(len) //5D=101B a.bit.length=3
#7、字符串魔法
#str = "aLEx"
# s2 = "root"
# a = s1.title() //title让每个单词首字母大写
# b = s1.upper() //把每个小写字母转为大写
# c = str.lower() //把大写字母转为小写
# print(a) // ALEx
# print(b) //ALEX
# print(c) //alex
#8、统计字符串中字符出现次数
#test = "erererrtrtrttytyty"
#b = test.count("er") //统计er在字符串test中出现的次数
# c = test.count('t',1,9) //统计t在字符串的第1和第9个字符中出现的次数
# print(b) // 3
# print(c)
#练习:输入3次对应用户名及密码,错误三次就失败
# count = 0 //输入3次对应用户名及密码,错误三次就失败
# while count < 3:
# user = input('>>>')
# passwd = input('<<<')
# if user == 'WYC' and passwd == '123':
# print("Welcome!")
# count += 1
#9、设置填充字符或字符位置
# test = "asddfghjk"
# a = test.ljust(20,"*") //设置宽度,并将内容居中
# # 20 代指总长度
# # * 空白未知填充,一个字符,可有可无
# b = test.rjust(20,"#")
# c = test.center(20,"$")
# print(a)
# print(b)
# print(c)
#
# asddfghjk***********
# ###########asddfghjk
# $$$$$asddfghjk$$$$$$
#10、查找字符的位置并输出
# 从开始往后找,找到第一个之后,获取其位置
# test = "qwertyuiop"
# a = test.find('r')
# print(a) // 3
# 11、字符串中是否只包含 字母和数字
# test = "123"
# v = test.isalnum()
# print(v)
# str
# 12、是否是字母,汉字
# test = "as2df"
# v = test.isalpha()
# print(v)
# 13、当前输入是否是数字
# test = "二" # 1,②
# v1 = test.isdecimal()
# v2 = test.isdigit()
# v3 = test.isnumeric()
# print(v1,v2,v3)
# 14、是否存在不可显示的字符
# \t 制表符
# \n 换行
# test = "oiuas\tdfkj"
# v = test.isprintable()
# print(v)
# 15、判断是否全部是空格
# test = ""
# v = test.isspace()
# print(v)
#16、join将字符串中的每一个元素按照指定分隔符进行拼接
# a = "asdasdasdasd"
# b = "_"
# c = b.join(a)
# print(c)
#a_s_d_a_s_d_a_s_d_a_s_d
#17、判断是否全部是大小写 和 转换为大小写
# test = "Alex"
# v1 = test.islower()
# v2 = test.lower()
# print(v1, v2)
# v1 = test.isupper()
# v2 = test.upper()
# print(v1,v2)
#18、将指定字符串替换为指定字符串
# test = "ererererererer"
# a = test.replace("er","zx")
# b = test.replace("er","zx",1)
# c = test.replace("er","zx",4) //替换test字符串中前4个er为zx
# print(a)
# print(b)
# print(c)
# zxzxzxzxzxzxzx
# zxerererererer
# zxzxzxzxererer
# 19、split分割为指定个数
# test = "qwertyuiop"
# a = test.split("w",2)
# b = test.rsplit("w",2)
# print(a)
# print(b)
# ['q', 'ertyuiop']
# ['q', 'ertyuiop']
# 20、swapcase大小写转换
# test = "aLeWcF"
# a = test.swapcase()
# print(a)
# AlEwCf
# 二、黑魔法
#1、for循环
# for 变量名 in 字符串:
# 变量名
# break
# continue
#2、len获取字符串长度
# index = 0
# while index < len(test):
# v = test[index]
# print(v)
#
# index += 1
# print('=======')
# 3、切片:提取第2个字符和第5个字符之间的内容
# test = "qwertyasdfghjklpoi"
# a = test[2:5]
# print(a) //ert
# test = "qweqweqwe"
# a = len(test)
# print(a) //9
#4、获取连续或不连续的数字,
# # Python2中直接创建在内容中
# # python3中只有for循环时,才一个一个创建
# 帮助创建连续的数字,通过设置步长来指定不连续
# v = range(0, 100, 5)
# a = range(10)
# b = range(1,10)
# c = range(1,100,5) // 帮助创建连续的数字,通过设置步长来指定不连续
# i=0
# print(a)
# while i< 10:
# print(a[i])
# i +=1
# 0
# 1
# 2
# 3
# 4
# 5
# 6
# 7
# 8
# 9