10 examples of 'str to bool python' in Python

Every line of 'str to bool python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
2332def _str_to_bool(bool_str):
2333 if len(bool_str) > 1:
2334 bool_str = bool_str[0]
2335 return unicode(bool_str).upper() == 'T'
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

23def _str_to_bool(in_str):
24 if "t" in in_str.lower():
25 return True
26 else:
27 return False
40def convert_str_to_bool(str: str) -> bool:
41 """
42 Convert string to boolean.
43
44 :param str: given string
45 :return: converted string
46 """
47 try:
48 return str.lower() in ('yes', 'true', 't', '1')
49 except AttributeError as err:
50 logger.error(err)
181def to_bool(s):
182 if s.lower() in ("yes", "1", "true", "t", "y"):
183 return True
184 return False
493def as_bool(b):
494 return str(b).lower() in {"1", "true", "yes", "t", "on"}
25def str2bool(v):
26 """
27 argparse does not support True or False in python
28 """
29 return v.lower() in ("true", "t", "1")
29def str2bool(v):
30 return v.lower() in ("yes", "true", "t", "1")
43def bool2str(b):
44 if b:
45 return "true"
46 else:
47 return "false"
67def to_bool(s):
68 """
69 Converts the given string to a boolean.
70 """
71 return s.lower() in ('1', 'true', 'yes', 'on')
53def to_bool(val):
54 if not val:
55 return False
56
57 if isinstance(val, str):
58 return val.lower() not in ('0', 'false', 'f', 'off')
59 else:
60 return bool(val)

Related snippets