⊗pyPmLsEl 41 of 208 menu

Getting a Single Element of a List in Python

You can access the elements of a list in the same way as you access the characters of a string: the first element has the number 0, the second has the number 1, and so on. These numbers are called the indices of the elements of the list. Let's look at an example:

lst = ['a', 'b', 'c', 'd', 'e'] print(lst[0]) # 'a' print(lst[1]) # 'b' print(lst[2]) # 'c'

Given a list:

lst = [1, 2, 3, 4, 5]

Print the first element of this list.

Given a list:

lst = [1, 2, 3, 4, 5]

Print the second element of this list.

The following code is given:

lst = [1, 2, 3, 4, 5] print(lst[-1])

Tell me what will be output to the console.

The following code is given:

lst = [2, 4, 6, 8] res = lst[3] - lst[0] print(res)

Tell me what will be output to the console.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline