Python string slicing via index

PHOTO EMBED

Tue Apr 04 2023 03:22:33 GMT+0000 (Coordinated Universal Time)

Saved by @tofufu #python

word = 'Python'

word[:2]   # character from the beginning to position 2 (excluded)
# 'Py'
word[4:]   # characters from position 4 (included) to the end
# 'on'
word[-2:]  # characters from the second-last (included) to the end
# 'on'
content_copyCOPY

https://docs.python.org/3/tutorial/introduction.html