- 2

CD,12?

What is the output? print("abcefd".replace("cd","12")) Output: abcefd #Replace simply means to "replace" so I though the code would be ab12ed as just replacing the number strings? Any idea why the answer was abcded?

8th Apr 2019, 9:07 PM
tristach605
tristach605 - avatar
3 Answers
+ 1
The output is "abcefd" because the string "cd" (both letters need to be together) is not found in "abcefd. If the original string was "abcd" then the output would be "ab12".
8th Apr 2019, 10:42 PM
Diego
Diego - avatar
0
Just ran this code and the output was ab12efd. Are you sure the code you're showing us is the original one? Perhaps you removed/added something.
8th Apr 2019, 9:18 PM
Diego
Diego - avatar
0
Pardone me, Diego! I did make a mistake when transcribing. I'll edit the original post now. Thanks for pointing out my error.
8th Apr 2019, 10:18 PM
tristach605
tristach605 - avatar