Back to Python Notes
Topic #18

Slicing Strings

Slicing pulls out parts of a string using index ranges, from single characters to every other letter. It is one of Python's most elegant and frequently used tricks.


Slicing

You can return a range of characters by using the slice syntax.

Specify the start index and the end index, separated by a colon, to return a part of the string.

Example

b = "Hello, World!"
  print(b[2:5])

Note: The first character has index 0.


Slice From the Start

By leaving out the start index, the range will start at the first character:

Example

b = "Hello, World!"
  print(b[:5])

Slice To the End

By leaving out the end index, the range will go to the end:

Example

b = "Hello, World!"
  print(b[2:])

Negative Indexing

Example

b = "Hello, World!"
  print(b[-5:-2])

Want to go beyond the notes?

Join Coding Now Tech Institute's Python course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Slicing Strings – FAQs

Quick answers about learning Slicing Strings in Python.

This free note from Coding Now Tech Institute explains Slicing Strings in Python — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Python topic on Coding Now Tech Institute, including Slicing Strings, is 100% free with no signup required.
With focused practice, most students grasp Slicing Strings in 1–3 days from these notes; pairing it with Coding Now Tech Institute's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now