How do I change the string to boolean?

Asked 2 years ago, Updated 2 years ago, 188 views

How do I change the string to boolean?

def strToBool(s):
    return str.toupper() == "TRUE"

Is there any function that Python provides other than what I define together?

string python bool conversion

2022-09-22 22:25

1 Answers

There is no string->bullion conversion function provided by the Python built-in function.

You can write bool(str) together This is false only when str="; all other cases return True.

To replace a string with a bool type, write it down in the question

def strToBool(s):
    return str.toupper() == "TRUE"

The best way is to use it.


2022-09-22 22:25

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.