0 votes
1 view
in Python by (33.2k points)

Does anyone know how to do the conversion from a string to a boolean in Python?

The reason I asked this is because I learned int("string"), from here. I tried bool("string") but always got True.

>>> bool("False") 


1 Answer

0 votes
by (107k points)

 You can use the following way to get the desired output:-

def str2bool(v):

   return str(v).lower() in ("yes", "true", "t", "1")



Related questions

0 votes
1 answer
+3 votes
2 answers
0 votes
1 answer
asked Sep 17, 2019 in Python by Sammy (47.8k points)
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !