Python String Remove Last n Characters

preview_player
Показать описание
Python String Remove last several letters

In Python last characters of a string can be removed with indexes like:

Example Remove last n characters

n = 5
'Python is cool'[:-n]
print('Python is cool'[:-n])

Example Remove n-th characters

n = 1
print('Python'[:n] + 'Python'[n+1:])

Example Remove n-th sequence

n = 1
m = 3
print('Python'[:n] + 'Python'[n+m:])

---------------------------------------------------------------------------------------------------------------------------------------------------------------
Code store

Socials

If you really find this channel useful and enjoy the content, you're welcome to support me and this channel with a small donation via PayPal.

Рекомендации по теме
Комментарии
Автор

lots of other methods overcomplicating, this is the only one that works easy

henry