Python - Convert String Truth values to Boolean Last Updated : 15 Jul, 2025 Comments Improve Suggest changes 1 Likes Like Report Converting string truth values like "True" and "False" into their corresponding boolean values in Python is a straightforward yet useful operation. Methods such as dictionaries, direct comparison, and built-in functions offer simple and efficient ways to achieve this transformation for various use cases.Using eval() Functioneval() function in Python is used to evaluate a string as a Python expression and convert it into the corresponding object Python s = "True" # Convert string to boolean using eval boolean_value = eval(s) print(boolean_value) OutputTrue Explanation :eval(s) function evaluates the string s as a Python expression, converting it into its corresponding Python object, in this case, the boolean value True.The result, stored in boolean_value, is then printed, showing the evaluated boolean value True. Using str.lower() with ComparisonUsing str.lower() with comparison allows you to convert a string to lowercase before performing a case-insensitive comparison. This ensures that the comparison ignores differences in letter casing between the two strings. Python s = "True" # Convert string to boolean by comparing lowercase value boolean_value = s.strip().lower() == "true" print(boolean_value) OutputTrue Explanation :s.strip().lower() method first removes any leading or trailing spaces using strip(), then converts the string to lowercase using lower(). This ensures the comparison is case-insensitive.The string is then compared to "true", and if they match, the result is True; otherwise, it is False. The result is stored in boolean_value and printed.Using a Dictionary for LookupUsing a dictionary for lookup allows you to map specific string values to corresponding boolean values or other types. This provides an efficient way to perform case-insensitive or custom comparisons by leveraging the dictionary's key-value pairs. Python s = "False" # Dictionary to map string values to boolean bool_map = {"true": True, "false": False} # Convert string to boolean using the dictionary boolean_value = bool_map.get(s.strip().lower(), False) print(boolean_value) OutputFalse Explanation :The bool_map dictionary maps the lowercase string values "true" and "false" to their corresponding boolean values True and False.The s.strip().lower() converts the input string to lowercase and removes any extra spaces, then bool_map.get() retrieves the corresponding boolean value, defaulting to False if the string doesn't match. The result is stored in boolean_value and printed. Create Quiz Comment M manjeet_04 Follow 1 Improve M manjeet_04 Follow 1 Improve Article Tags : Python Python Programs Python list-programs Python string-programs Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 4 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 3 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 3 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 3 min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 6 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 5 min read Build a REST API using Flask - Python 3 min read Building a Simple API with Django REST Framework 3 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like