Q:

Write a python program to find all occurrences of “USA” in a given string ignoring the case.

0

Find all occurrences of a substring in a given string by ignoring the case

Write a program to find all occurrences of “USA” in a given string ignoring the case.

Given:

str1 = "Welcome to USA. usa awesome, isn't it?"

Expected Outcome:

The USA count is: 2

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Hint:

Use the string function count()

Solution:

str1 = "Welcome to USA. usa awesome, isn't it?"
sub_string = "USA"

# convert string to lowercase
temp_str = str1.lower()

# use count function
count = temp_str.count(sub_string.lower())
print("The USA count is:", count)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now