How to remove the last 2 characters of a string in Python

2 Answers

0 votes
s = "python"
  
n = 2
s = s[:-n]
  
print(s)
  
  
  
'''
run:
  
pyth
  
'''

 



answered Nov 3, 2021 by avibootz
0 votes
s = "python"
  
s = s[:-2]
  
print(s)
  
  
  
'''
run:
  
pyth
  
'''

 



answered Nov 3, 2021 by avibootz

Related questions

1 answer 218 views
1 answer 219 views
1 answer 215 views
2 answers 308 views
1 answer 222 views
1 answer 200 views
...