Home > Mobile >  Remove sentences with a certain character prefix
Remove sentences with a certain character prefix

Time:01-31

I want to remove the $//$ character along with the sentence after the character.

sentence = "The weather forecast for today is mostly sunny $//$ The forecast $//$ for tomorrow will be rainy. The rest of the week..."

expected output : "The weather forecast for today is mostly sunny"

any help will be appreciated

CodePudding user response:

sentence.split("$//$")[0] will do the job

CodePudding user response:

First you need to split the sentence using .split

word.split("$//$")

then when is it split there is 2 parts, so we can use a index to seperate it.

We should use [0] for the first element which is the part you want.

So the code is:

word.split("$//$")
print(word[0])
  •  Tags:  
  • Related