Home>

Is there a way to assign multiple lines at once in python?
For example, if I want to assign to lines 1, 3, 4
list = [1,1,1,1,1,1,1,]
list [0] = 3
list [2] = 3
list [3] = 3
If I want to assign the same number like
In the slide, 134 does not work because it is not an arithmetic sequence.
Please give me a detailed answer.

  • Answer # 1

    lst = [1, 1, 1, 1, 1, 1, 1,]
    for idx in [0, 2, 3]:
        lst [idx] = 3

Related articles