167k views
3 votes
Question Set 22.1 Using the count method, find the number of occurrences of the character 's' in the string 'mississippi'.2.2 In the string 'mississippi', replace all occurrences of the substring 'iss' with 'ox'.2.3 Find the index of the first occurrence of 'p' in 'mississippi'.

User Hridya Pv
by
3.4k points

1 Answer

3 votes

Answer:

# Program is written in python

# 22.1 Using the count method, find the number of occurrences of the character 's' in the string 'mississippi'.

# initializing string

Stringtocheck = "mississippi"

# using count() to get count of s

counter = Stringtocheck.count('s')

# printing result

print ("Count of s is : " + str(counter))

# 2.2 In the string 'mississippi', replace all occurrences of the substring 'iss' with 'ox

# Here, we'll make use of replace() method

# Prints the string by replacing iss by ox

print(Stringtocheck.replace("iss", "ox"))

#2.3 Find the index of the first occurrence of 'p' in 'mississippi'

# declare substring

substring = 'p'

# Find index

index = Stringtocheck.find(substring)

# Print index

print(index)

# End of program

User JiNexus
by
3.7k points