Examveda

What will be the output of the following code:
my_string = "Hello, World!"
print(my_string.replace("Hello", "Hi"))

A. "Hi, World!"

B. "Hello, Hi!"

C. "Hi, Hi!"

D. "Hi"

Answer: Option A

Solution (By Examveda Team)

The replace() function in Python replaces all occurrences of a specified substring with another substring in a given string. In this case, "Hello" is replaced with "Hi" in the string "Hello, World!", resulting in "Hi, World!".

This Question Belongs to Python Program >> Python Built In Functions

Join The Discussion

Related Questions on Python Built In Functions