The finditer function of the regex library can help us perform the task of finding the occurrences of the substring in the target string and the start function can return the resultant index of each of them.
You are getting this error message because you do not have any function thats name is res.
So change your code to:
test_str = "all in all is not the all of all "
test_sub = "all"
print("The main string is : " + test_str)
print("The substring to find : " + test_sub)
res = [i.start() for i in re.finditer(test_sub, test_str)]
print("The start indices of the substrings are : " + str(res))
And its output is:
The main string is : all in all is not the all of all
The substring to find : all
The start indices of the substrings are : [0, 7, 22, 29]
Hope this will help you to solve your probelm.