remove last character from a string in python

main.py
my_string = "hello world"
new_string = my_string[:-1]
print(new_string)
72 chars
4 lines

Output:

main.py
hello worl
11 chars
2 lines

In Python, you can use string slicing to remove the last character from a string. Slicing a string involves specifying a range of indices to include in the substring. By excluding the last index in the range, you can remove the last character from the string.

related categories

gistlibby LogSnag