Ad

How Do I Use Substring In The Following Condition

- 1 answer

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?

Ad

Answer

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

Extract_16charcters_after32index = Text[32:16:-1]
Ad
source: stackoverflow.com
Ad