Hướng dẫn how do you create multiple empty lists in python? - làm cách nào để bạn tạo nhiều danh sách trống trong python?

Mã bên dưới sẽ tự động 'tạo' chính nó. Đối với mỗi lần lặp, lệnh sau sẽ được ban hành:

ListNumber = []number = []

Trong đó số là giá trị của i trong vòng lặp.number is the value of i in the loop.

x = 3 # Amount of lists you want to create
for i in range(1, x+1):
    command = "" # This line is here to clear out the previous command
    command = "list" + str(i) + " = []"
    exec(command)

Kết quả của đoạn mã cụ thể này là ba biến: List1, List2 và List3 đang được tạo và mỗi biến được gán một danh sách trống.

Bạn có thể khái quát điều này để thực tế làm bất cứ điều gì bạn muốn. Xin lưu ý rằng bạn không thể đặt điều này vào một chức năng theo như tôi biết, vì cách các biến và biến toàn cầu hoạt động.

name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).

for i in range(1, amount+1):
    command_variable = ""
    command_variable = name + str(i) + " = " + value
    exec(command_variable)

ITDOES không tạo danh sách độc lập, nhưng các biến đề cập đến cùng một danh sách (trống)! & NBSP;

list1, list2, list3, list4 =

name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).

for i in range(1, amount+1):
    command_variable = ""
    command_variable = name + str(i) + " = " + value
    exec(command_variable)
44
name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).

for i in range(1, amount+1):
    command_variable = ""
    command_variable = name + str(i) + " = " + value
    exec(command_variable)
45
name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).

for i in range(1, amount+1):
    command_variable = ""
    command_variable = name + str(i) + " = " + value
    exec(command_variable)
3

name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).

for i in range(1, amount+1):
    command_variable = ""
    command_variable = name + str(i) + " = " + value
    exec(command_variable)
7
name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).

for i in range(1, amount+1):
    command_variable = ""
    command_variable = name + str(i) + " = " + value
    exec(command_variable)
53
name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).

for i in range(1, amount+1):
    command_variable = ""
    command_variable = name + str(i) + " = " + value
    exec(command_variable)
54
name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).

for i in range(1, amount+1):
    command_variable = ""
    command_variable = name + str(i) + " = " + value
    exec(command_variable)
55

  • name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    7
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    8
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    9
    The initialized lists are : 
    List 1 : [1]
    List 2 : [2]
    List 3 : [3]
    List 4 : [4]
    0
  • name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    7
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    8
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    9
    The initialized lists are all the same: 
    List 1 : ["hello there"]
    List 2 : ["hello there"]
    List 3 : ["hello there"]
    List 4 : ["hello there"]
    0
  • ITDOES không tạo danh sách độc lập, nhưng các biến đề cập đến cùng một danh sách (trống)! & NBSP;

    list1, list2, list3, list4 =

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    44
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    45
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    3

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    7
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    53
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    54
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    55

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    7
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    8
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    9
    The initialized lists are : 
    List 1 : [1]
    List 2 : [2]
    List 3 : [3]
    List 4 : [4]
    0

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    7
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    8
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    9
    The initialized lists are all the same: 
    List 1 : ["hello there"]
    List 2 : ["hello there"]
    List 3 : ["hello there"]
    List 4 : ["hello there"]
    0
    Using loops

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    7
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    8
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    9list1, list2, list3, list4 0

    Python3

    Làm thế nào để bạn tạo nhiều danh sách tại một thời điểm trong Python?

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    5
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    6

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    7
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    8

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    7
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    4
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    5
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    6

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    5
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    6

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    7
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    4
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    5
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    6

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    7
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    8
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    9
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    03=9
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    05

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    5
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    6

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    7
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    4
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    5
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    6

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    7
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    8
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    9
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    03=9
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    05

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    5
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    6

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    7
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    4
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    5
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    6

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    7
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    8
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    9
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    03=9
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    05

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    5
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    6

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    7
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    4
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    5
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    6

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    7
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    8
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    9=0

    Output:

    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []

    Phương thức số 2: Sử dụng Phương thức DefaultDict () & NBSP;Using defaultdict() Method 

    Đây là một phương pháp khác nhau và cũng thực hiện một tiện ích hơi khác so với hai phương pháp trên được thảo luận. Điều này tạo ra một từ điển với một tên cụ thể và chúng tôi có tùy chọn để tạo bất kỳ số khóa nào và thực hiện các hoạt động phụ lục ngay lập tức khi chúng được khởi tạo bởi danh sách. & NBSP;

    Python3

    =1 =2

    =3= =5=6.

    =8=9([] 0

    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    5
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    0

    =8([] 4([] 0

    The initialized lists are : 
    List 1 : [1]
    List 2 : [2]
    List 3 : [3]
    List 4 : [4]
    5
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    0

    =8([] 9([] 0

    The initialized lists are all the same: 
    List 1 : ["hello there"]
    List 2 : ["hello there"]
    List 3 : ["hello there"]
    List 4 : ["hello there"]
    5
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    0

    =8for4([] 0

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    3
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    0

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    5
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    6

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    7
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    8

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    7
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    0

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    5
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    6

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    7
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    4
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    5
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    6

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    7
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    8
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    9
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    03=9
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    05

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    5
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    6

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    7
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    4
    The initialized lists are : 
    List 1 : [1]
    List 2 : [2]
    List 3 : [3]
    List 4 : [4]
    5
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    6

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    7
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    8
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    9
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    03([] 4
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    05

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    5
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    6

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    7
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    4
    The initialized lists are all the same: 
    List 1 : ["hello there"]
    List 2 : ["hello there"]
    List 3 : ["hello there"]
    List 4 : ["hello there"]
    5
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    6

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    7
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    8
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    9
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    03([] 9
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    05

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    5
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    6

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    7
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    4
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    3
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    6

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    7
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    8
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    9
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    03for4
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    05

    Output:

    The initialized lists are : 
    List 1 : [1]
    List 2 : [2]
    List 3 : [3]
    List 4 : [4]

    Phương pháp 4: Sử dụng * toán tử: & nbsp; Using * operator: 

    ITDOES không tạo danh sách độc lập, nhưng các biến đề cập đến cùng một danh sách (trống)! & NBSP;does not create independent lists, but variables referring to the same (empty) list! 

    Python3

    list1, list2, list3, list4 =

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    44
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    45
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    3

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    47
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    48
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    0

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    5
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    6

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    7
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    53
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    54
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    55

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    7
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    0

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    5
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    6

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    7
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    4
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    5
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    6

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    7
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    8
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    9
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    03=9
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    05

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    5
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    6

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    7
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    4
    The initialized lists are : 
    List 1 : [1]
    List 2 : [2]
    List 3 : [3]
    List 4 : [4]
    5
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    6

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    7
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    8
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    9
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    03([] 4
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    05

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    5
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    6

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    7
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    4
    The initialized lists are all the same: 
    List 1 : ["hello there"]
    List 2 : ["hello there"]
    List 3 : ["hello there"]
    List 4 : ["hello there"]
    5
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    6

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    7
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    8
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    9
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    03([] 9
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    05

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    5
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    6

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    7
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    4
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    3
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    6

    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    7
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    8
    The initialized lists are : 
    List 1 : []
    List 2 : []
    List 3 : []
    List 4 : []
    9
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    03for4
    name = "my_var" # This has to be a string, variables like my_var1, my_var2 will be created.
    value = "[]" # This also has to be a string, even when you want to assign integers! When you want to assign a string "3", you'd do this: value = "'3'"
    amount = 5 # This must be an integer. This many variables will be created (my_var1, my_var2 ... my_var5).
    
    for i in range(1, amount+1):
        command_variable = ""
        command_variable = name + str(i) + " = " + value
        exec(command_variable)
    
    05

    Output:

    The initialized lists are all the same: 
    List 1 : ["hello there"]
    List 2 : ["hello there"]
    List 3 : ["hello there"]
    List 4 : ["hello there"]


    Làm thế nào để bạn tạo nhiều danh sách tại một thời điểm trong Python?

    Sử dụng toán tử + Toán tử + thực hiện một công việc thẳng về phía trước là tham gia các danh sách với nhau.Chúng tôi chỉ áp dụng toán tử giữa tên của danh sách và kết quả cuối cùng được lưu trữ trong danh sách lớn hơn.Trình tự của các yếu tố trong danh sách được bảo tồn. The + operator does a straight forward job of joining the lists together. We just apply the operator between the name of the lists and the final result is stored in the bigger list. The sequence of the elements in the lists are preserved.

    Bạn có thể có nhiều danh sách trong Python không?

    Bạn có thể chỉ cần sử dụng một vòng lặp để tạo danh sách n.use a for loop to create n lists.

    Làm thế nào một danh sách trống có thể được tạo ra?

    Một danh sách trống trong Python có thể được tạo theo hai cách, bằng cách sử dụng dấu ngoặc vuông [] hoặc bằng cách sử dụng hàm tạo danh sách ().by using square brackets [] or by using the list() constructor.

    Làm thế nào để bạn thêm một danh sách trống vào một danh sách trong Python?

    Sử dụng phương thức danh sách Python EXPEND () để nối vào danh sách trống.Phương pháp này sẽ nối các phần tử (đối tượng) vào cuối danh sách trống.Bạn cũng có thể sử dụng toán tử + để kết hợp danh sách các yếu tố vào một danh sách trống.. This method will append elements (object) to the end of an empty list. You can also use the + operator to concatenate a list of elements to an empty list.