0

question about replace() method

What is the meaning of 2 in this one line code ? https://code.sololearn.com/cia11smGV1Yx

11th Dec 2017, 9:08 PM
NIMA
NIMA - avatar
4 Respuestas
+ 4
It's how many times it's replacing. In your example, it'll replace the first 2 'i' chars with 'z' which is why the remaining 'i' chars weren't replaced. Change the number to 4 and run it again, it should replace the other two 'i' chars with 'z' also.
11th Dec 2017, 9:25 PM
AgentSmith
+ 6
Here's the official blurb on the built in string methods https://docs.python.org/3/library/stdtypes.html#string-methods
11th Dec 2017, 11:10 PM
David Ashton
David Ashton - avatar
+ 4
Btw, I forgot to mention, if you omit that argument altogether, it'll replace all instead of only replacing a certain amount of times.
11th Dec 2017, 9:35 PM
AgentSmith
+ 1
perform the replace twice.
11th Dec 2017, 9:24 PM
John Wells
John Wells - avatar