Learn Python like a Professional! Take You from 0 to Hero
In this Python lecture, we will learn about the Boolean.
" Boolean values are the two constant objects False and True ".
" Boolean values are the two constant objects False and True ".
We can use built-in bool() function or comparison operators to get the boolean result.
Let's look at the Boolean examples-
a = 1
b = 2
print( a < b )
print(bool( a > b))
print(bool( a == b))
>> False
We can also use bool() function
print(bool( a != b)) # Returns True when the argument is true, False otherwise
>> True
Check The Type
We have built-in function type() to check the type of object.
type(True)
type(false)
>> bool
type(0)
type('value')
Cast Into Boolean
We can use built-in bool() method to cast the object in the boolean type
1.Integer to boolean
1.Integer to boolean
bool(1)
bool(0) # Notice O is casted as false in boolean
2.String to Boolean
bool('value')
bool(' ') # Notice Space is casted as false in boolean
Boolean to Integer
int(True) # Notice True is casted as 1 in integer type
int(False) # Notice False is casted as 0 in integer type
Also, try to cast boolean to string
In the next Blog, we will discuss Q&A first.
https://sngurukuls247.blogspot.com/2018/09/python-ninja-bootcamp-13-q-first.html
......................................................................................................................................
Instagram-
https://www.instagram.com/python.india/
View the Jupyter Notebook for this lecture
Download the Jupyter Notebook for this lecture
https://sngurukuls247.blogspot.com/2018/09/python-ninja-bootcamp-13-q-first.html
......................................................................................................................................
Follow the link below to access Free Python Lectures-
https://www.youtube.com/channel/UCENc9qI7_r8KMf6-_1R1xnwInstagram-
https://www.instagram.com/python.india/
View the Jupyter Notebook for this lecture
Feel free contact me on-
Email - sn.gurukul24.7uk@gmail.com
No comments:
Post a Comment