How to find the substring in Python String

Find the Substring in Python

In this challenge, the user enters a string and a substring. You have to print the number of times that the substring occurs in the given string. String traversal will take place from left to right, not from right to left.

Python Program To Add Two Numbers

How to make a Instagram bot in python

How To Open Command Prompt Using Python

NOTE: String letters are case-sensitive.

Input Format

The first line of input contains the original string. The next line contains the substring.

Constraints
Each character in the string is an ascii character.

Output Format

Output the integer number indicating the total number of occurrences of the substring in the original string.

Sample Input:

ABCDCDC
CDC

How To Convert String To Float In Python

Sample Output:

2

Solution:

a=input()
b=input()
c=0
x=len(b)
for i in range(len(a)-len(b)+1):
   if b==a[i:i+x]:
       c+=1
print(c)

Django vs Node Js a comparative guide 2021

How to make a url shortener in python just 5 lines of code

How to make text to speech converter in python

How to make a strong password generator in python

Learn Python MySQL

Making A Bank Account Program In Python

Related Search Queries:

Find a String in Python

Find the substring in Python

One comment on “How to find the substring in Python String”

  • Tech Fizz May 30, 2022
    Reply

    Thankyou sir

Write a comment