Close Menu
    Facebook X (Twitter) Instagram
    Oixiesoft
    • Home
    • Services
      • WordPress Malware Removal
      • Fix WordPress Errors
      • WordPress Website Development
    • Articles
    • Contact
    Oixiesoft
    Home»Tutorial»Python»Python Booleans
    Python

    Python Booleans

    Editorial StaffBy Editorial StaffUpdated:April 18, 2022No Comments2 Mins Read
    Share
    Facebook Twitter LinkedIn Pinterest Email

    In this tutorial, we will learn about Python Boolean. The Booleans data type represent one of two values: True or False.

    Boolean Values

    In programming, we often need to know if a condition is True or False so that we can perform action based on the results.

    We can evaluate any expression to get one of two answers, True or False.

    When we compare two values, the expression is evaluated and Python returns the Boolean answer:

    Example

    print(15 > 19)
    print(6 == 6)
    print(11 < 9)
    
    Output
    False
    True
    False

    When we run a condition in an if statement, Python returns True or False:

    Example

    x = 100
    y = 40
    
    if y > x:
      print("y is greater than x")
    else:
      print("y is not greater than x")
    

     

    Output
    y is not greater than x

    Evaluate Values and Variables

    The bool() function allows us to evaluate any valueto get True or False in return,

    Example

    print(bool("Welcome"))
    print(bool(25))
    

     

    Output
    True
    True

     

    Most Values are True

    If any value has some sort of content, it is evaluted to True.

    Any number is True, except 0.

    Any string is True, except empty strings.

    Any set, list, tuple, and dictionary is True, except empty ones.

    Example

    print(bool("xyz"))
    print(bool(143))
    print(bool(["orange", "mango", "banana"]))
    

     

    Output
    True
    True
    True

     

    Some Values are False

    In fact, there are not many values that evaluate to False, except empty values, such as (), [], {}, “”, the number 0, and the value None. And of course the value False evaluates to False.

    Example

    print(bool(()))
    print(bool([]))
    print(bool(False))
    print(bool(None))
    print(bool({}))
    print(bool(0))
    print(bool(""))
    

     

    Output
    False
    False
    False
    False
    False
    False
    False
    Share. Facebook Twitter Pinterest LinkedIn WhatsApp Reddit Tumblr Email
    Editorial Staff

    Related Posts

    CodeIgniter vs Laravel: A Detailed Side-by-Side Comparison

    Python Arrays

    Python Lambda

    • Python Introduction
    • Python Home
    • Python Keywords and Identifiers
    • Python Variables & Constants
    • Python Operators
    • Python Booleans
    • Python Lists
    • Python Tuples
    • Python Sets
    • Python if…else Statement
    • Python Loops
    • Python Functions
    • Python Lambda
    • Python Arrays
    Services
    • Web Development
    • Mobile Application Development
    • WordPress Malware Removal Service
    • Website Design
    • WordPress Development
    • Magento Development
    • Shopify Development
    • SEO Services
    Blog
    • How to Fix the Error Establishing a Database Connection
    • Ping List WordPress
    • How To Fix Japanese Keyword Hack
    • How to remove Malware from WordPress
    Hire Developers
    • Hire WordPress Developer
    • Hire Shopify Developer
    Contact Info
    • Oixiesoft Technologies
      A-40, Block A, I thum Tower, Sector 62, Noida
    • [email protected]
    • Privacy Policy
    • About Us
    • Contact Us
    © 2025 OixieSoft Technologies

    Type above and press Enter to search. Press Esc to cancel.