The most elegant way would probably be to simply check empty string if it’s true or falsy in Python.
Use if statement evaluated to
True in a Boolean context if they are empty or not. They are not equal to
if not myString:
Example check an empty string in Python
my_string = "" if not my_string: print("The string is empty") else: print("The string is not empty")
Do comment if you have any doubts and suggestions on this Python string topic.
Note: IDE: PyCharm 2021.1.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.