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 120 views
1 answer 121 views
1 answer 118 views
2 answers 169 views
1 answer 145 views
1 answer 114 views
...