Skip to content

Slicing in Python


Slicing from a list or string can be achieved in Python using the following syntax.




nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
print nums[5:8]
#[5, 6, 7]

Slicing from string can be done like..

url = 'https//'
print url[7:-4]

See also  Add n days to today's date in Python

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.