Converting from a string to boolean in Python
In Python, you can use the bool() function to convert a string to a boolean.
In Python, you can use the bool() function to convert a string to a boolean. For example:
Convert a string to a boolean in Python
string = "True"
boolean = bool(string)
print(boolean) # Output: True
<div class="alert alert-info flex not-prose">![]()
<span class="hidden md:block">Watch a video course</span>Python - The Practical Guide</div>
Note that the bool() function in Python returns True when the input string is non-empty and False when the input string is empty.
Regarding the specific string values of "True" and "False", both will be evaluated as True by the bool() function since they are non-empty strings.