Monday 29 May 2023

Boolean variables in Python

Boolean variable can hold either True or False, and the type ‘bool’ represents a Boolean type.

 

Example

is_raining = True
is_raining = False

Please note that the first letter starts with capital case where T in True, F in False

 

boolean_variables.py

is_raining = True

if is_raining:
    print('It is raining')
else:
    print('It is not raining')

is_raining = False

if is_raining:
    print('It is raining')
else:
    print('It is not raining')


print('type of is_raining : ', type(is_raining))

In the above example, we define a variable ‘is_raining’ to specify whether it is raining or not.

 


Output

It is raining
It is not raining
type of is_raining :  <class 'bool'>


 

 

Previous                                                 Next                                                 Home

No comments:

Post a Comment