string1 = ‘abcdefghijk’
I need to extract a substring from 4th position for a length of 2 characters
I tried this Python code and I get a syntax error:
substring1 = string1(3:2)
(the result in substring should be ‘de’ if it works)
Thanks for help.
String s = (String1[3:4]); // Returns “de”
Thanks, it works with [3:5] (as [3:4] returns only ‘d’).
pos4th = 4 - 1 # 3
len2 = pos4th + 2 # 5
abc = 'abcdefghijk'
de = abc[pos4th:len2]
print abc, de, ENTER, pos4th, len2
Substring function in python extract sub strings with the sense of StartIndex , EndIndex-1
Indeed, left side value of
: is inclusive; while right side value is exclusive.