# -*- coding:utf-8 -*- # python 的字符串处理 # 查找 s = "abc" # print s.find("b") # 找到返回下标 # print s.find("ab") # 返回第一个的下标 # print s.find("aba") # 找不到返回-1 # 分割 s = "abcaw12dsgswdg" # print s.split('12') # 大小写转换 s1 = "a" s2 = "B" # print s1.upper() # print s2.lower() # 截取 s = "1234567" # print s[2:5] # 从下标2 到(5-1) # print s[2:] # print s[:4] # print s[:-1] # python支持负下标,最后一位为-1 ,输出到(-1-1)位 # 追加 s = "abc" t = "def" # print s + t # 支持直接相加(追加) # 替换 s = "1,2,3" # print s.replace(",", "#") # 连接 s = ["a", "b", "c"] # 将列表连接为字符串 # print "#".join(s) # 反转 s = "1234567" # print s[::2] # 其实就是截取的有了步长(默认第三个参数为1),当这个参数为-1时,倒叙输出 # print s[::-1]
分类: Python
0 条评论