有没有办法一次附加具有相同值的多个列表 - Python

Is there a way to append multiple list with the same value at once - Python

对于我的学校项目,我试图一次将一个值附加到多个列表。 我正在尝试做的一个例子:

list1 = [1, 2, 3]
list2 = [4, 5, 6]

假设我正在尝试将 7 添加到它们的末尾。而不是做:

list1.append(7)
list2.append(7)

有什么方法可以在一行中做到这一点。我试过了,但没用:

(list1, list2).append(7)

您可以使用 for 循环来完成。见下文:

a = [1, 2, 3]
b = [3, 4, 6]
for i in (a,b):
    i.append(7)
    
print(a)
print(b)

这给了我们:

[1, 2, 3, 7]
[3, 4, 6, 7]