How to print characters from a string starting from 3rd to 5th in Python?

PythonServer Side ProgrammingProgramming

Slicing feature in Python helps fetch a substring from original string. Slice operator [:] needs two operands. First operand is an integer representing index of starting character of slice. Second operand is index of character next to slice. Recalling that index of sequence starts from 0,

>>> string = 'abcdefghij'
>>> string[2:5]

Here 3rd character of slice ‘cde’ starts at index 2 and ends at 4, so second operand is given as 5

Published on 28-Dec-2017 05:27:53