How to add items to list in Python

This Python tutorial will help you to learn how to add items to list in Python programming. To make this tutorial easy to understand we will show you adding elements to list in Python with some easy examples.

The list in python is very much similar to list used in other programming languages.

You can store integers as well as strings element in a list in python. Even you can store both integers and string values in a list at the same time.

You may also read,

Add items to list in Python

To add items to list in Python create a list first.

my_list =[12,15,'hello']

Now to add items to the list you can simply use append() method

my_list =[12,15,'hello']
print(my_list)
my_list.append(25)
print(my_list)

Output:

[12, 15, 'hello']
[12, 15, 'hello', 25]

You may also learn,



Add item to a specific position in list Python Programming

This method is widely used. But there is also another method. Let’s check it out:

my_list =[12,15,'hello']
print(my_list)
my_list = my_list +[26]
print(my_list)

Output:

[12, 15, 'hello']
[12, 15, 'hello', 26]

Add elements to list in Python temporarily

Here I will show you how to add items to list in Python but the items will not be stored in the list. It will just show you.

Just take a look at it:

my_list =[12,15,'hello']
print(my_list+[20,25])
print(my_list)

Output:

[12, 15, 'hello', 20, 25]
[12, 15, 'hello']

If you have any doubts you may comment in the below comment section.

Leave a Reply

Your email address will not be published. Required fields are marked *