BOOLEAN IN PYTHON

machine learning from scratch

Not all variables can take numerical values for themselves. The boolean data type in python consists of two value i.e. True or False. Bool ( ) generally accepts one parameter, which on testing procedure yields True or False output. If no parameter is passed, default output is False in boolean in python.

 >>> print (bool(1))
>>> a = True 
>>> print (a)
>>> print (3>4)       # test if 3 > 4
>>> str1 = "sush"
>>> str1.islower()   #test if string contains lower case

OUTPUT:
True
True
False
True

Note the keywords True and False must have an Upper Case first letter. Using a lowercase true returns an error.

click here

SOME CONCEPTS ABOUT BOOLEAN
  1. If any contents are present, then it is true.
  2. Number is True, except 0.
  3. String is True, except empty strings.
  4. List, tuple, set, and dictionary are True, except empty ones.
>>> print('For True:  ',int(True))
>>> print('For False: ', int(False))

Output:
For True:   1
For False:  0
Projects with free Codes

This page is contributed by Diwas & Sunil . If you like AIHUB and would like to contribute, you can also write an article & mail your article to  itsaihub@gmail.com . See your articles appearing on AI HUB platform and help other AI Enthusiast.

About Diwas

🚀 I'm Diwas Pandey, a Computer Engineer with an unyielding passion for Artificial Intelligence, currently pursuing a Master's in Computer Science at Washington State University, USA. As a dedicated blogger at AIHUBPROJECTS.COM, I share insights into the cutting-edge developments in AI, and as a Freelancer, I leverage my technical expertise to craft innovative solutions. Join me in bridging the gap between technology and healthcare as we shape a brighter future together! 🌍🤖🔬

View all posts by Diwas →

3 Comments on “BOOLEAN IN PYTHON”

  1. Heya i am for the first time here. I found this
    board and I find It really useful & it helped me
    out much. I hope to give something back and help others like
    you helped me.

Leave a Reply

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