索引和分片同样适用
带头不带尾
支持第三个参数
也就是步长
当这个参数为负值的时候
截取的字符串为倒序
ord() # 单个字符转换为ASCII
chr() #
print(os.listdir()) m = re.match('/(.*)/(.*)/(.*)','/Users/liu/Desktop/vuedemo/vuxdemo') # 字典的key是唯一的 无序 存在就修改 不存在就创建 #删除 del pop # update 合并两个字典 重复的就替换, 不重复的添加 w = {x:ord(x) for x in 'xiaohongandxiaohua'} print(w) print(w.keys()) print(w.values()) print(w.items()) for i in w : print(i,' = > ',w[i]) print(w.get('u')) print(w['u']) print(type(w)) r = [i for i in range(10)] print(type(r)) print(r) d2 = dict.fromkeys([1,2,3],'hello') print(d2) squares = [ i*2 for i in range(10)] print(squares) l = [] # enumerate 输出格式(下标,值) for index,value in enumerate(l): print(index,value) #字符操作 name = "usra local bina" print(name.capitalize()) print(name.count("a")) print(name.center(90,"!")) print(name.endswith('a')) #字母替换 s = str.maketrans('asdf','1234') print('aaasssdddfff'.translate(s)) print(name[2]) n = "0123456789" print(n[4:9]) # 带头不带尾 print(n.replace('0','aaaaa') ) e = '1,2,3,4,56,' print(e.split(','))
s = 'spammy,'
s1 = s[:3] + 'xx' + s[5:]
print(s1)
s2 = s.replace('mm', 'xx')
print(s2)
s3 = s * 3
print(s3.replace('mm','xx',1))
s4 = s.join(s)
print(s4)
s5 = s4.split(',')
print(s5)
print('hello %s %d'%('xiaoming',123))
不可变类型不可以在原处操作
可变类型