python remove string from string

>>> papa = 'papa is a good man'
>>> papa.replace('papa', '')
' is a good man'

Here is what the above code is Doing:
1. We create a string variable called papa.
2. We use the replace() method to replace the word ‘papa’ with an empty string.
3. We print the result.

As you can see, the word ‘papa’ is no longer in the string.

You can also use the replace() method to replace multiple words at once. For example:

>>> papa = ‘papa is a good man’
>>> papa.replace(‘papa’, ‘daddy’).replace(‘man’, ‘person’)
‘daddy is a good person’

Here’s what the above code is doing:
1. We create a string variable called papa.
2. We use the replace() method to replace the word ‘papa’ with ‘daddy’.
3. We use the replace() method to replace the word ‘man’ with ‘person’.
4. We print the result.

As you can see, the words ‘papa’ and ‘man’ are no longer in the string.

You can also use the replace() method to replace multiple words at once. For example:

>>> papa = ‘papa is a good man’
>>> papa.replace(‘papa’, ‘daddy’).replace(‘man’, ‘person’)
‘daddy is a good person’

Here’s what the above code is doing:
1. We create a string variable called papa.
2. We use the replace() method to replace the word ‘papa’ with ‘daddy’.
3. We use the replace() method to replace the word ‘man’ with ‘person’.
4. We print the result.

As you can see, the words ‘papa’ and ‘man’ are no longer in the string.