Creating simple list

In this blog, we will create a simple list. Displaying complete list and first element of a list.

>> numbers = [1,2,3,4,5,6]
>>> print(numbers)
[1, 2, 3, 4, 5, 6]
>>> print(numbers[0])

In the above code, we have created a list called numbers which contains only integer values. Used print function to display complete list. Index number 0 to display first element of list. Index number always start with 0. First element of a list will have index number 0, second element will have index number 1 and so on.

>> cars = [‘Tata’,’Renault’,’Hyundai’,’Ford’,’Toyota’]
>>> print(cars)
[‘Tata’, ‘Renault’, ‘Hyundai’, ‘Ford’, ‘Toyota’]
>>> print(‘First Element:%s’%cars[0])
First Element:Tata
>>> print(‘Second Element:%s’%cars[1])
Second Element:Renault

Above code contain cars list. We have displayed first and second elements of a list.

>> country = [‘India’,’USA’,’China’,’England’,’Finland’]
>>> print(country)
[‘India’, ‘USA’, ‘China’, ‘England’, ‘Finland’]
>>> print(‘First element:%s   Second element:%s’%(country[0],country[1]))
First element:India   Second element:USA

Above code contain country list, Displaying first and second elements.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s