-2

I need to extract the last two characters of a phrase, but I don't know how as there isn't a minus 0.

1 Answers1

0

You can try

a = "abcd"
a[-2:]

output

'cd'

By putting a negative number in a string slicing you will get the number of characters from the end of the string.

Gabio
  • 9,126
  • 3
  • 12
  • 32
Leo Arad
  • 4,452
  • 2
  • 6
  • 17