• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / Python / Convert False to 0 in Python

Convert False to 0 in Python

July 6, 2022 Leave a Comment

To convert the boolean value False to 0 in Python, you can use int(). int() converts False to 0 explicitly.

print(int(False))

#Output:
0

You can also convert False to 0 implicitly in the following way.

print(False == 0)

#Output:
True

When working with different variable types in Python, the ability to easily convert between those types can be valuable.

One such situation is if you have boolean variables and want to convert them to integers.

In Python, you can use the int() function to explicitly convert boolean values True and False into 1 and 0, respectively.

Below shows you how you can use int() to convert False to 0 explicitly.

print(int(False))

#Output:
0

If want to implicitly convert False to 0, you can let Python do it for you as False is equal to 0.

print(False == 0)

#Output:
True

Convert True to 1 in Python

If you want to go the other way and convert True into an integer, you can use int().

True is equal to 1, but if you want to do the conversion explicitly. then you can use int() in the following way.

Below shows you how to convert True to 1 in Python.

print(int(False))

#Output:
1

Hopefully this article has been useful for you to learn how to convert False to 0 in Python.

Other Articles You'll Also Like:

  • 1.  Using Python to Calculate Average of List of Numbers
  • 2.  pandas nsmallest – Find Smallest Values in Series or Dataframe
  • 3.  Using Python to Convert Tuple to String
  • 4.  Using Python turtle Module to Draw Square
  • 5.  Check if List is Subset of Another List in Python
  • 6.  How to Add Commas to Numbers in Python
  • 7.  Using Python to Sort Two Lists Together
  • 8.  Convert Set to List in Python
  • 9.  How to Check if Variable Exists in Python
  • 10.  Using Python to Split String into Dictionary

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy