首页 > 解决方案 > Display the number of substrings along with the substring

问题描述

The input should be manual and must be able to count the number of substrings for any kind of input and also display them

标签: pythonsubstring

解决方案


# Function to print all sub strings 
def subString(s, n): 
    # Pick starting point in outer loop 
    # and lengths of different strings for 
    # a given starting point
    c=0
    for i in range(n): 
        for len in range(i+1,n+1): 
            print(s[i: len]); #prints substring
            c+=1
    print("Number of substrings:",c)

# Driver program to test above function 
s = "abcd"; 
subString(s,len(s));

推荐阅读