Skip to Main Content
Blog

Count String in Python

Count String in Python

def main():
    """
    Counts the number of non-overlapping occurrences of a substring in a string.
    """

    txt = input("Enter string: ").lower()
    key = input("Enter key: ").lower()
    ctr = txt.count(key)
    print(ctr)


if __name__ == "__main__":
    main()