Here is a python code to find all possible sub strings in a given string. String is a collection of characters, and we can perform multiple operations on strings like search, merge, delete, compare, etc.,
# taking string as input string = input('Enter the string: ') # lenght of the string n = len(string) # formula for total number of substrings n*(n+1)/2 total = (n*(n+1)) // 2 print('Total number of substrings are:', total) # for ever char traverse ever char which is ahead for i in range(n): for j in range(i, n): # printing sustring in range i to j print(string[i:j+1])
OUTPUT:
Enter the string: programming9 Total number of substrings are: 78 p pr pro prog progr progra program programm programmi programmin programming programming9 r ro rog rogr rogra rogram rogramm rogrammi rogrammin rogramming rogramming9 o og ogr ogra ogram ogramm ogrammi ogrammin ogramming ogramming9 g gr gra gram gramm grammi grammin gramming gramming9 r ra ram ramm rammi rammin ramming ramming9 a am amm ammi ammin amming amming9 m mm mmi mmin mming mming9 m mi min ming ming9 i in ing ing9 n ng ng9 g g9 9