标签:less python dex exp rip 列表 join log 个数
#字符串操作
#定义字符串
a = "let‘s go"
#字符串切片
print("helloworld"[2:]) #通过索引获取字符串中的字符,和列表切片同理
#关键字 in
print("llo" in "helloworld") #返回TRUE或False
#字符串拼接
#可以用+拼接字符串
#join实现拼接
a = "123"
b = "456"
d = "789"
c=‘***‘.join([a,b,d]) #用*拼接a,b,c
#返回123***456***789
#% 格式化输出字符串
print(‘there are some examples‘)
print(‘%s are some examples‘ %‘there‘)
#字符串的内置方法
st = "hello kitty{name}"
st.count("t") #统计t的个数
st.capitalize #首字母大写
st.center(50."#") #居中
st.endswith(‘ty‘) #以某个内容结尾
st.startswith(‘he‘) #以某个内容开头
st.expandtabs(tabsize = 20) #修改缩进
st.find(‘t‘) #寻找,返回索引值
st.format(name = "haha") #格式化输出的另一种方式
print(st.index(‘t‘)) #返回t的索引值
print(‘My tLtle‘.lower()) #将字符串里的字母全部转换为小写
print(‘My tLtle‘.upper()) #将字符串里的字母全部转换为大写
print(‘\tMy tLtle\n‘.strip()) #将字符串里不显示的内容去掉
print(‘My title title‘.replace(‘itle‘,‘lesson‘,1)) #替换,replace(‘被替换的值‘,‘替换后的内容‘,1(替换几个))
print(‘My title title‘.split(‘i‘,1)) #分割,split(‘分割值‘,分割次数)
标签:less python dex exp rip 列表 join log 个数
原文地址:http://www.cnblogs.com/SHENGXIN/p/7421204.html