+ 1
String replace method...though it was easy
Took this one from a challenge: >>> a = "abcefd" >>> print(a.replace('cd','12')) Output: 'abcefd' # why is that??????? I was expecting --> 'ab1ef2' . Please explain a.replace('cd','12') is 'cd' given as an interval from c to d included, so 'cefd' , since it is not recognized as a substring??? Or shall I consider 'cd' as separate 'c' and 'd' ? Usually if you look for tutorials about replace() method on strings, the typical example are always given with substrings of the original string, never seen something like that above.
1 Odpowiedź
+ 2
It replace a substring 'cd' with string '12' but because in your source string ('abcdefd') its not present the substring 'cd', no replacement happen