标签:字符串 获取 mat tab expand strip() tabs 判断字符串 center
##判断字符串
# s = "Alex SB"
# ret = "SB" in s
# print(ret)
##判断字符串是否在数组中
# li = [‘alex‘,‘eric‘,‘rain‘]
# ret ="alex" in li
# print(ret)
##大小写转换
# temp = "hey"
# print(temp)
# temp_new = temp.upper()
# print(temp_new)
##资费类型
# temp = ‘hey‘
# help(type(temp))
##获取可表示其二进制的最短位数
# n1 = 4
# ret = n1.bit_length()
# print(ret)
# #首字母大写
# a1 = "alex"
# ret = a1.capitalize()
# print(ret)
##中间
# a2 = "alex"
# ret = a2.center(20,‘*‘)
# print(ret)
# #找字符串出现次数
# a3 = "alex isalph"
# ret = a3.count("al",0,5)
# print(ret)
# temp = "hello"
# #获取字符串大于等于0小于等于2的位置
# print(temp.endswith(‘e‘,0,2))
##空格转换
# content = "hello\t1998"
# print(content)
# print(content.expandtabs(20))
##找字符的位置
# s = "alex hello"
# print(s.find("o"))
# s = "hello {0}, age {1}"
# print(s)
# #{0}占位符
# new1 = s.format(‘alex‘,19)
# print(new1)
#join连接
# li =["alex","eric"]
# s = "******".join(li)
# print(s)
##去空格
# s = " alex "
# #news = s.lstrip()去左边空格
# #news = s.rstrip()去右边空格
# news = s.strip()
# print(news)
##替换
# s = "alex is hd"
# ret = s.replace("al","bb",1)
# print(ret)
##分割
# s = "alexalex"
# ret = s.split("e")
# print(ret)
# #大小写互换
# s = "bdasjhSD"
# print(s.swapcase())
标签:字符串 获取 mat tab expand strip() tabs 判断字符串 center
原文地址:http://www.cnblogs.com/myywsy/p/7677133.html