# Python Boolean

In programming, sometimes we want values to be either True or False which has assigned in programming as Boolean values.

We can compare two values directly which will return True or False accordingly as a Boolean value.

### Example

```print(10 == 10)
print(10 == 9)
print(10 > 9)
print(10 < 9)```

### Output

```True
False
True
False```

In Python, we use bool() function to check True or False.

bool() function always returns True until we don’t pass something from the following–

• 0
• empty string
• empty list, tuple, dictionary
• other empty objects like a set
• anything like a function which returns a function

### Example

```print(bool(0))  # passing 0
print(bool(""))  # passing an empty string
print(bool([]))  # passing an empty list
print(bool({}))  # passing an empty dict
print(bool(()))  # passing an empty set```

### Output

```False
False
False
False
False```

bool() will return True if the value is not an empty one.

### Example

```print(bool(1))
print(bool(12.2))
print(bool(23j))
print(bool("aString"))
print(bool([1, 2, "Hello"]))
print(bool({"Key":"value"}))```

### Output

```True
True
True
True
True
True```

• Make money with Python in 2022
Did you know that data science was the fifth most common job on LinkedIn in 2017? Did you know that the demand for Python programmers is expected to grow by 19% from 2020-2021? Did you know that Python is one of the fastest-growing programming languages, and it will likely continue to expand as its adoption…
• Top 15 Python Libraries For Data Science in 2022
Introduction In this informative article, we look at the most important Python Libraries For Data Science and explain how their distinct features may help you develop your data science knowledge. Python has a rich data science library environment. It’s almost impossible to cover everything in a single article. As a consequence, we’ve compiled a list…
• Top 15 Python Libraries For Machine Learning in 2022
Introduction  In today’s digital environment, artificial intelligence (AI) and machine learning (ML) are getting more and more popular. Because of their growing popularity, machine learning technologies and algorithms should be mastered by IT workers. Specifically, Python machine learning libraries are what we are investigating today. We give individuals a head start on the new year…
• File Explorer in Python using Tkinter
Introduction Welcome to copyassignment.com. In this tutorial, we are going to learn File Explorer in Python using the Tkinter module. What is basically a file explorer? A file explorer is nothing but an application that is used to manage certain files and folders on your device where we can open, edit, copy, delete and move…
• Drawing Application in Python Tkinter
Introduction In this article, we will design and construct a basic Drawing Application in Python Tkinter GUI, where we can simply draw something on the canvas using a pencil and erase with an eraser, as well as the ability to change the thickness of a pencil and eraser. We may also modify the canvas’s background…

## 4 thoughts on “Python Boolean”

1. shiva ram reddy says:

The output of the 1st example in python boolean section is wrong
print(10==10)
print(10=9)
print(10>9)
print(109
false 10<9

please try to crosscheck it

1. Harry says:

which line?

1. shiva ram reddy says:

the entire output of that example is wrong

1. Harry says:

we have checked the code and have run it again, there are no errors
{"ft_lang_label":"__label__en","ft_lang_prob":0.86586076,"math_prob":0.73863596,"size":3305,"snap":"2022-40-2023-06","text_gpt3_token_len":736,"char_repetition_ratio":0.12602241,"word_repetition_ratio":0.018832391,"special_character_ratio":0.23570348,"punctuation_ratio":0.07023411,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.95937467,"pos_list":[0,1,2,3,4,5,6,7,8],"im_url_duplicate_count":[null,null,null,null,null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-09-27T23:23:38Z\",\"WARC-Record-ID\":\"<urn:uuid:61ce459a-c474-4941-a33d-30a47e234b95>\",\"Content-Length\":\"101011\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:6e71db9d-20b8-4dfa-a83e-d7016d849715>\",\"WARC-Concurrent-To\":\"<urn:uuid:be65bbc4-01d0-4c54-be25-f761720c3982>\",\"WARC-IP-Address\":\"194.163.38.220\",\"WARC-Target-URI\":\"https://copyassignment.com/python/python-boolean/\",\"WARC-Payload-Digest\":\"sha1:JYB7OUAQPJEESG5EHBILGMDQVRKROYP4\",\"WARC-Block-Digest\":\"sha1:UBNMUYNBF3CI3ZNK3REXZYGM22JDBK2Y\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-40/CC-MAIN-2022-40_segments_1664030335059.31_warc_CC-MAIN-20220927225413-20220928015413-00111.warc.gz\"}"}