Slicing in Python
Advertisements
Slicing from a list or string can be achieved in Python using the following syntax.
Syntax
list[start:end:step]
Examples
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//poopcode.com' print url[7:-4] #poopcode