copy(简介)
对数据进行深拷贝与浅拷贝
copy(参数列表)
deepcopy | 深拷贝(多维列表/通用) |
copy | 浅拷贝(常规列表) |
copy(参考代码)
区别(深拷贝 / 浅拷贝 / 赋值)
import copy
""" 浅拷贝 """
numbers = ["one", "two", "three"]
cp1 = copy.copy(numbers)
cp1.append("four")
print("原本:", numbers) # >>> 原本: ['one', 'two', 'three']
print("复制后:", cp1) # >>> 复制后: ['one', 'two', 'three', 'four']
""" 深拷贝 """
box = ["one", "two", "three", ["four", ["five", "six"]]]
lis = copy.deepcopy(box)
lis[-1].append("add")
print("原本:", box) # >>> 原本: ['one', 'two', 'three', ['four', ['five', 'six']]]
print("复制后:", lis) # >>> 复制后: ['one', 'two', 'three', ['four', ['five', 'six'], 'add']]
""" 赋值 """
test = ["1", "2", "3"]
new = test
new.append("4")
print("常规赋值:", test) # >>> 常规赋值: ['1', '2', '3', '4']
print("赋值后", new) # >>> 赋值后 ['1', '2', '3', '4']
queue(简介)
队列:对数据进行顺序排列,先进先出或后进先出的规则。
queue(参考代码)
综合例子
import queue
# FIFO队列-先进先出
"""
q = queue.Queue()
for i in range(5):
q.put(i)
while not q.empty():
print(q.get())
"""
# LIFO队列-后进先出
"""
q = queue.LifoQueue()
for i in range(5):
q.put(i)
while not q.empty():
print(q.get())
"""
string(参数列表)
string.ascii_letters | 包含a-Z的所有大小写字母 |
string.digits | 包含0~9的所有数字 |