s1 = '^^^^^success^^^^' print(s1.strip('^')) # success 本身并没有修改 是产生了新的结果 print(s1) # ^^^^^success^^^^ # 查看内存地址 print(id(s1)) # 2168071404040 print(id(s1.strip('^'))) # 2168071377504
s2 = [111, 222, 333] print(s2.extend([11, 22, 33, 44, 55])) # None 空 print(s2) # [111, 222, 333, 11, 22, 33, 44, 55] # 查看内存地址 print(id(s2)) # 1390036469896 s2.append(11111111) print(id(s2)) # 1390036469896
先进先出
new_list = [] # 先进 new_list.append('jack') new_list.append('zoe') new_list.append('lucas') # 先出 # 方式一 for i in new_list: print(i) # jack zoe lucas # 方式二 print(new_list.pop(0)) # jack print(new_list.pop(0)) # zoe print(new_list.pop(0)) # lucas
先进后出
new_list = [] # 先进 new_list.append('jack') new_list.append('zoe') new_list.append('lucas') # 后出 print(new_list.pop()) # lucas print(new_list.pop()) # zoe print(new_list.pop()) # jack