第一天:
字符串索引与切片
# s = "ABCDEFGHIGK"#首位为第0位即A为第0位
# #索引
# # s1 = s[0]
# # print(s1)
# # s2 = s[2]
# # print(s2)
# s3 = s[-1]
# print(s3)#k
#切片:顾头不顾尾
# s4 = s[0:4]
# print(s4)
# s5 = s[0:]
# print(s5)
# s6 = s[:]
# print(s6)
# s7 = s[0:]
# print(s7)
# s8 = s[0:0]
# print(s8)
# s9 = s[0:-1]
# print(s9)#ABCDEFGHIG
# s = "ABCDEFGHIGK"#[首:尾:步长]步长为2时隔1个字符输出一个字符例ABC隔B输出AC
# s10 = s[0:5:2]
# print(s10)#ACE
# s11 = s[0:4:2]
# print(s11)#AC
#ps:也是顾头不顾尾
# s12 = s[::3]
# print(s12)
#s = "ABCDEFGHIGK"
# s13 = s[3::-2]
# print(s13)
# s14 = s[1:2]
# print(s14)
# s ="AbcdefG"
#全大写,全小写
# s2 = s.upper()
# print(s2)#全大写
# s3 = s.lower()
# print(s3)#全小写
# s_str = "acEQ1"
# you_input = input("请输入验证码,不区分大小写:")
# if you_input.lower() == s_str.lower():
# print("成功")
# else:
# print("失败")
#大小写翻转
# s4 = s.swapcase()
# print(s4)#大小写反转
# s ="abcdefG*bagkasgjdKKGAS akdkafAGKD123adfjaAJDLJASD"
# s5 = s.capitalize()
# print(s5)#首字母大写,其余变为小写
# s6 = s.title()
# print(s6)#每个被(特殊符号或数字)隔开的单词,首字母大写,其余小写
#居中,空白填充
#s = "alexWUsir"
#s7 = s.center(20, "$")
# print(s7)#$$$$$alexWUsir$$$$$$
# s = "alex\tsir\tqwe"
# s8 = s.expandtabs()
# print(s8)#alex sir qwe
# s = "alex二哥123"
# #公共方法,其他关键字都能用
# s22 = len(s)
# print(s22)#返回共有多少个字符
# #以什么开头
# s = "alexWUsir"
# s23 = s.startswith("alex", 2, 4)
# print(s23)
|