How to substring a string in Python - Java @ Desk

Wednesday, January 1, 2025

How to substring a string in Python

Substring a string in Python is done using the below syntax -
str = 'OriginalString';
substring_start = str[:8]
print("Substring first 8 characters - " + substring_start)

substring_end = str[8:]
print("Substring last 8 characters - " + substring_end)

Output -

Substring first 8 characters - Original
Substring last 8 characters - String







No comments:

Post a Comment