0
how can I append various numbers at one time?
3 Answers
+ 6
@Venkatesh Pitta is right: extend() method add all items of the passed list/tupple to the targeted list, while append() method will add a list/tupple as only once new item ^^
list = [1,2,3]
list.append(4) # list is now [1,2,3,4]
list.append([5,6]) # list is now [1,2,3,4,[5,6]]
list.extend([7,8,9]) # list is now [1,2,3,4,[5,6],7,8,9]
Anyway, you can simply use list concatenation operator '+'...
list = [1,2,3]
list = list + [4,5,6] # list is now [1,2,3,4,5,6]
# or shortener:
list += [7,8,9] # list is now [1,2,3,4,5,6,7,8,9]
+ 2
look into extend method on lists.
example:
l = []
l.extend((1,2,3,4))
print(l)
## [1, 2, 3, 4] is the output.
- 1
The append method only takes a single argument. In order to add multiple values at once, you'll have to append a list of values.
example:
list_1 = []
list_1.append([1,2,3])