Question d’entretien chez Microsoft

Coding question: replace a char in a string with another string.

Réponses aux questions d'entretien

Utilisateur anonyme

2 oct. 2017

# Python Code def replaceCharacter(s, characterToBeReplaced, replacement): retVal = "" for i in s: if i == characterToBeReplaced: retVal += replacement else: retVal += i return retVal print replaceCharacter("HowIsaPresidentYourFrat", "a", "SAMMY")

Utilisateur anonyme

14 août 2018

def replaceChar(s, ch, replacement): print(s.replace(ch, replacement))