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 168 views
1 answer 97 views
1 answer 104 views
1 answer 94 views
1 answer 118 views
1 answer 117 views
1 answer 110 views
...