How to get the last 3 characters of a string in Python

3 Answers

0 votes
s = "python"
  
last3Characters = s[-3:]
  
print(last3Characters)
  
  
  
  
'''
run:
  
hon
 
'''

 



answered Nov 3, 2021 by avibootz
0 votes
s = "python"

n = 3  
last3Characters = s[-n:]
  
print(last3Characters)
  
  
  
  
'''
run:
  
hon
 
'''

 



answered Nov 3, 2021 by avibootz
0 votes
s = "python"

n = 3  
last3Characters = s[len(s) - n:]
  
print(last3Characters)
  
  
  
  
'''
run:
  
hon
 
'''

 



answered Nov 3, 2021 by avibootz

Related questions

2 answers 183 views
1 answer 114 views
1 answer 117 views
1 answer 102 views
1 answer 130 views
1 answer 127 views
1 answer 118 views
...