OKPEDIA PYTHON LISTA EN

How to read first element of a list in Python

To get the first element of a list in python, type the name of the list and the zero index in square brackets.

namelist[0]

The first element of a list always has index zero.

Example

Create a list with four elements.

>>> color=['blue', 'red', 'green', 'yellow']

Get the first element of the list

>>> color[0]

The output result is

'blue'

Python reads the top element of the list.

https://how.okpedia.org/en/python/how-to-read-first-element-of-a-list-in-python


Report us an error or send a suggestion to improve this page


Python List


FacebookTwitterLinkedinLinkedin