• Register
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

12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

1 vote
 
Best answer

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

 

13 9 6
94,260 points

Related questions

0 votes
1 answer 2 views
2 views
Problem: Could anyone kindly assist me in resolving this uncaught error? “Find all substrings of a string python”
asked Mar 29 tuhin1 48.9k points
0 votes
1 answer 8 views
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!
asked Mar 10 Mashhoodch 13k points
0 votes
1 answer 4 views
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
asked Mar 29 tuhin1 48.9k points
1 vote
1 answer 116 views
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?
asked Apr 22, 2020 samhaz 5k points
0 votes
1 answer 3 views
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.
asked Mar 29 tuhin1 48.9k points
0 votes
1 answer 2 views
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?
asked Mar 29 tuhin1 48.9k points
0 votes
1 answer 4 views
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!
asked Mar 10 Mashhoodch 13k points
0 votes
1 answer 3 views
3 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?
asked Mar 29 tuhin1 48.9k points
0 votes
1 answer 3 views
3 views
Problem: The operation must be exported or contain an intent-filter, which is why I got the error of Find a substring in a string.
asked Mar 29 tuhin1 48.9k points
0 votes
1 answer 3 views
3 views
Problem: I can't seem to find a solution; could you please help me “Find if a string is a substring of another java”?
asked Mar 29 tuhin1 48.9k points