How to access list in Python?

0 votes
Can someone help me with understanding list in Python? I am a beginner in Python and finding it difficult to understand List.
Mar 4 in Python by Trisha
24 views

1 answer to this question.

0 votes

A list is created by adding comma separated values in [ ]

list1 = ['a', 'b', 1, 2];
list2 = [1, 2, 3, 4, 5, 6, 7 ];
print "list1[0]: ", list1[0]
print "list2[1:5]: ", list2[1:5]

Output:

list1[0]: a
list2[1:5]: [2,3,4,5]

You can update the value simply by assigning new value:

list2[3] = 8
print "list2[3]: ", list2[3]

Output:
list2[3]: 8

Hope this helps.

answered Mar 4 by Priyaj
• 56,520 points

Related Questions In Python

+2 votes
11 answers
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
69 views
0 votes
1 answer

How to Reverse a list in Python

You can use the reversed function in ...READ MORE

answered Sep 28, 2018 in Python by SDeb
• 13,160 points
66 views
0 votes
1 answer

List comprehension on a nested list - How to do it in Python?

Not sure what your desired output is, ...READ MORE

answered Nov 21, 2018 in Python by Nymeria
• 3,520 points
78 views
+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 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 176 views
0 votes
1 answer

How to implement Linked List in Python?

You can use Deque that works better than linked list ...READ MORE

answered Oct 26, 2018 in Python by Priyaj
• 56,520 points
56 views
+1 vote
1 answer

How to create plots using python matplotlib in IPython notebook?

I think you should try: I used %matplotlib inline in ...READ MORE

answered Aug 8, 2018 in Python by Priyaj
• 56,520 points
117 views