Home > database >  how do i use substring in the following condition
how do i use substring in the following condition

Time:03-24

I have a string with 80 characters length I am trying to substring this characters at certain index I did the following

Extract_32charcters_From_Begining = Text[0:32]
Extract_16charcters_after32index = Text[32:16]

in the above example I expected to get the first 32 characters at the beginning of the text then extract 16 characters after index 32 in the text. Extract_16charcters_after32index always returns 0 length. any idea what i am doing wrong ?

usually in PHP I do

substr($text, 32, 16);

isn't the results should be same in python?

CodePudding user response:

For that, you need a negative step value which is -1

Extract_16charcters_after32index = Text[32:16:-1]
  • Related