Programming with Python

  1. Home
  2. Docs
  3. Programming with Python
  4. String manipulation in python
  5. String slices in python

String slices in python

In python, the term ‘string slice’ refers to a part of the string, where strings are sliced using a range of indices. It fetches characters in the range specified by two index operands separated by a colon.

If the first operands is omitted, the range starts at zero index.

If the second operand is omitted, the range goes up to the end of the string.

e.g.,

s='pythonpoint'
print(s[2:5])
print(s[:6])
print(s[3:])
Output-
tho
python
honpoint

This is all about string slices in python.

Was this article helpful to you? Yes No

How can we help?