0

So, I have a string, for example:

string = '34567'

I know that string[-1] will return me '7', but how do I get like '567'? Because it doesn't work if I start from the middle:

string[2:-1] == '56'

Usually, since the last number doesn't count, you just add 1 to it, but in this case you can't do it

So how do I print '567'?

g_lob00
  • 3
  • 3

2 Answers2

0

but in this case you can't do it

You can by not providing it.

>>> '34567'[-3:]
'567'

Which basically asks for "the last 3 characters of the string"

DeepSpace
  • 78,697
  • 11
  • 109
  • 154
0

To get the last 3 characters of a string you slice this way:

string[-3:]
Omri
  • 483
  • 4
  • 12