-5

The string i needed to format is,

string = "How are you?     abcdef"

I need to remove the "abcdef" from the string.

tins johny
  • 195
  • 1
  • 13
  • `print(string.replace('abcdefg',''))` – vhadalgi Nov 25 '19 at 10:03
  • Duplicate of [How to remove all characters after a specific character in python?](https://stackoverflow.com/questions/904746/how-to-remove-all-characters-after-a-specific-character-in-python) – TylerH Nov 25 '19 at 15:40

1 Answers1

5
string = string.split('  ')[0]

Edit: Explanation. The line of code above will split the single string into a list of strings wherever there is a double space. It is important to note that whatever is split upon, will be removed. [0] then retrieves the first element in this newly formed list.

SarahJessica
  • 473
  • 1
  • 7
  • 18