-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
  • 8,225
  • 3
  • 8
  • 26
Leo Arad
  • 4,352
  • 2
  • 5
  • 17