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
- If any contents are present, then it is true.
- Number is True, except 0.
- String is True, except empty strings.
- 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 email@example.com . See your articles appearing on AI HUB platform and help other AI Enthusiast.