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 132 views
1 answer 135 views
1 answer 130 views
2 answers 184 views
1 answer 160 views
1 answer 125 views
...