Python Substring

November 1, 2019
text = '1234abcd'

# first N chars
text[:4]    # 1234

# 3rd-4th chars
text[2:4]   # 34

# last N chars
text[-2:]   # cd

# remove 1st char
text[1:]    # '234abcd'

# remove last char
text[:-1]   # '1234abc'
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.