python add list values 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: python push to list

append(): append the object to the end of the list.
insert(): inserts the object before the given index.
extend(): extends the list by appending elements from the iterable.

Tags:

Misc Example