replace() function in python is used for replace the charecter or a set of charecter(called string) with other chracter or set of character of a specified string.
<string variable name>.replace(<old string>,<new string>)
Write a Python program to get a string from a given string where all occurrences of its first char have been changed to '#'.
Sample String : 'array'
Expected Result : '#rr#y'
str1=input("Enter A string : ") char = str1[0] str1 = str1.replace(char, '$') print(str1)
Write a Python program to get a string from a given string where all occurrences of its first char have been changed to '#', except the first char itself.
Sample String : 'array'
Expected Result : 'arr#y'
str1=input("Enter A string : ") char = str1[0] str1 = str1.replace(char, '$') str1 = char + str1[1:] print(str1)