⊗pyPmSlSP 78 of 208 menu

Slice by Position in Python

If you want to create a slice from a position, only the starting index is specified before the colon. Let's print the characters of the string starting at index 2:

txt = 'abcde' res = txt[2:] print(res) # 'cde'

Given a string:

txt = '12345'

Get a slice of all its characters except the first one:

'2345'

Given a list:

lst = ['ab', 1, 'cd', 2, 'ef', 3, 4]

Get the following slice of its elements:

[2, 'ef', 3, 4]
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