Lists in Python

In this post, we will look how to create lists in python.

This type of data structure helps us to keep and process complex data stored.

Defining List in Python
Lets see a sample program where we define and print the list items.

# List  list1 = [ 1,2,3,4 ]
# 2D List
list2d = [
    [1,2,3],
    [4,5,6],
    [7,8,9],
    [10,11,12]
]

print(list2d)
print(list2d[2][1])   ## note index starts from 0

 

Output
When we run above program, we can see complete list print on screen alongwith element stored at list2d[2][1] position.

/Users/saket/PycharmProjects/1helloworld/venv/bin/python /Users/saket/PycharmProjects/1helloworld/looping.py
[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]
8
Process finished with exit code 0

 

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments