How can Python empty a string?
In Python, strings are immutable, which means that you cannot directly modify an existing string, but you can create a new empty string to replace the original one. You can clear a string by creating a new empty string.
- Assign an empty string to the original string variable again.
string = ""
- “The cat is not in the box.”
“The cat is outside the box.”
string = str()
Both methods will create a new empty string and assign it to the original string variable, effectively clearing the string content.