write your replace function in python
Steve D'Aprano
steve+python at pearwood.info
Thu Dec 14 23:11:11 EST 2017
On Thu, 14 Dec 2017 09:08 pm, ayaskant.mantu111 at gmail.com wrote:
> Hi,
>
> I want to replace the spaces in a sting with hyphen with my own replace
> function or with using the pre-defined replace function. Can anybody help me
> with this issue???
new_string = "string with spaces".replace(" ", "hyphen")
When in doubt, open the Python interpreter to a command prompt ">>> " and
enter:
help("")
to see the string methods. Other commands work too:
help(str.replace)
--
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.
More information about the Python-list
mailing list