Does Python have something like an empty string so you can do the following?
if mi_cadena == string.empty:
Regardless, what's the most elegant way to check if a string is empty in Python? I find it weird to check each time if the string is exactly
"" and I feel like there must be some easier way.
Empty strings are "falsies" , meaning they are considered false in a boolean context, so you can just say:
if not mi_cadena:
For sequences, (strings, lists, tuples), use the fact that empty sequences are false.
If your variable can be of some other type, then you should use
mi_cadena == "" . See the Evaluate to True/False documentation for other values that are false in boolean contexts.
For very specific cases it may be preferable and safer to use:
if "".__eq__(myString): . Check the link for the detailed explanation.