append integers to list python code example

Example 1: python append n numbers to list

# Basic syntax:
your_list.extend([element]*number)
# Where:
#	- element is the element you want to add to your_list
#	- number is the number of times you want it repeated

# Note, .extend modifies your_list in place

# Example usage:
your_list = [1, 2, 3]
your_list.extend([0]*5)
print(your_list)
--> [1, 2, 3, 0, 0, 0, 0, 0]

Example 2: append integer to list python

foo = [1, 2, 3, 4, 5]
foo.append(4)
foo.append([8,7])    
print(foo)            # [1, 2, 3, 4, 5, 4, [8, 7]]

Example 3: how to add numbers into a list python

a_list = [1, 2, 3]
integers_to_append = 4.
a_list. append(integers_to_append)
print(a_list)