Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created June 29, 2020 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IndhumathyChelliah/2f37ad9cd54e576a0d106ff340d5a97f to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/2f37ad9cd54e576a0d106ff340d5a97f to your computer and use it in GitHub Desktop.
#if count not specified, it replaces all occurences of substring
s1="red blue green red orange green"
print (s1.replace("red","aaaaa"))#Output:aaaaa blue green aaaaa orange green
#count is mentioned as 1. So only first occurence is replaced.
print (s1.replace("red","***",1))#Output:*** blue green red orange green
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment