How to add elements to a list in Python

0 votes
I want to declare a list in Python. After that, I would like to perform some list operations on it. How to do it?
Jul 23, 2019 in Python by Arvind
• 3,050 points
815 views

1 answer to this question.

0 votes

To initialize an empty list do this:

new_list = []

or

new_list = list()

To add elements to the list, use append

new_list.append(12)

To extend the list to include the elements from another list use extend
new_list.extend([1,2,3,4])
new_list 
[12,1,2,3,4]

To remove an element from a list use remove

new_list.remove(2)
answered Jul 23, 2019 by Neel
• 3,020 points

Related Questions In Python

0 votes
0 answers
0 votes
1 answer

Adding elements to a list in python

Use extend() instead: l = [5, 7, 12, ...READ MORE

answered Apr 23, 2018 in Python by Nietzsche's daemon
• 4,260 points
825 views
0 votes
1 answer

How to add a new line in Python?

You can use '\n' for a next ...READ MORE

answered May 2, 2018 in Python by aayushi
• 750 points
1,278 views
0 votes
1 answer

How to Print a List in Python

ou are using Python 2.x syntax with ...READ MORE

answered Aug 31, 2018 in Python by charlie_brown
• 7,720 points
1,106 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,466 views
0 votes
1 answer
0 votes
1 answer

How to get permutations of list or a set in Python?

Permutation is an arrangement of objects in ...READ MORE

answered Jul 11, 2019 in Python by Neel
• 3,020 points
8,932 views
0 votes
1 answer

How to find the greatest number in a list in Python?

1. By using max function -  highest = ...READ MORE

answered Aug 21, 2019 in Python by Neel
• 3,020 points
2,884 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP