How to remove the first and the last character from a string in Python

2 Answers

0 votes
s = "python"

s = s[1:-1]

print(s)



'''
run:

ytho

'''

 



answered Feb 25, 2021 by avibootz
0 votes
s = "python"

s = s.lstrip("p").rstrip("n")

print(s)



'''
run:

ytho

'''

 



answered Feb 25, 2021 by avibootz

Related questions

...