# How to find all substrings of a string python?

1 vote
19 views

## Problem:

Hello, good people of Kodlogs, I am a new student of Python programming language. The online course I am taking they are teaching me well. Every weekend they provide me with some problems to solve. This week, I have got the problem find all substrings of a string python. I don’t have any idea how to do this! I would appreciate your effort if you pull me up.

Many thanks

1 vote

## Solution:

Finding substring in a string is quite easy in python. You can easily find it by using a for-loop iteration over the given string length. As far as I come to know that you are a novice, I have another suitable solution for you. I deliberately figure out the built-in .substr(i, len) function for you. The function helps us to find the substring from a string within a wink. Let’s check how to use the function

``````def mySubString(str, x):
for i in range(x):
for len in range(i+1,x+1):
print(str[i: len]);

str = "gavin";
mySubString(str,len(str)); ``````

The above codes will produce an output

``````g
ga
gav
gavi
gavin
a
av
avi
avin
v
vi
vin
i
in
n``````

## Related questions

2 views
Problem: Could anyone kindly assist me in resolving this uncaught error? &ldquo;Find all substrings of a string python&rdquo;
8 views
Problem: how to I Solve this: get all substrings of a string python HELP! I need help understanding this: get all substrings of a string python Can someone please help solve this, I am new in python(). Someone have idea to solve this thanks!
4 views
Problem: I am stuck during learning as I have already mentioned in my question someone please cooperate me to continue my project-Thanks
1 vote
116 views
Problem: I wrote this code to find all occurrences of a substring in a string python: import re 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) print(" ... is not defined The first two ouput of this code is right but it throws error message after that. What should I do to run this code properly?
3 views
Problem: I'll make a submission for a response to my question. Please, I have searched the internet but have not found any useful material, and I am now having trouble continuing my studies.
2 views
Problem: As I mentioned in my previous query, I'm having difficulties with my learning; I've tried searching the web but haven't been able to find adequate information; could you assist me in continuing my project?
4 views
Problem: how to I Solve this: find index of substring in string python HELP! I need help understanding this: find index of substring in string python Can someone please help solve this, I am new in python(). Someone have idea to solve this thanks!