You are here: Home / Topics / Write a Python program to get a new string from a given string where "Is" has been added to the front. If the given string already begins with "Is" then return the string unchange

Write a Python program to get a new string from a given string where "Is" has been added to the front. If the given string already begins with "Is" then return the string unchange

Filed under: Python on 2023-09-23 06:51:37

def new_string(str):
 if len(str) >= 2 and str[:2] == "Is":
   return str
 return "Is" + str

print(new_string("Array"))
print(new_string("IsEmpty"))     

Output:

IsArray                                                                                                       
IsEmpty 


About Author:
M
Mr. Dubey     View Profile
Founder of MCQ Buddy. I just like to help others. This portal helps students in getting study material free. Share your stuff here so that others can get benefitted.