BOOLEANS AND TYPE CASTING IN PYTHON

 

 ALL ABOUT BOOLEAN  AND TYPE CASTING IN PYTHON


THIS IS CODE OF BOOLEAN  AND  TYPE-CASTING IN PYTHON YOU CAN COPY PASTE THIS CODE AND RUN 
THIS CODE AND SEE THE OUTPUT IN THIS CODE I HAVE COVER ALMOST WORK RELATED 
TO BOOLEAN  AND TYPECASTING 
x = bool(1) # x will be 1 print(type(x))
y = int(2.8) # y will be 2
print(type(y))
z = int("3") # z will be 3
print(type(z))
a = float(1) # x will be 1.0
print(type(a))
b = float(2.8) # y will be 2.8
print(type(b))
c = float("3") # z will be 3.0
print(type(c))
d= float("4.2") # w will be 4.2
print(type(d))
e = str("s1") # x will be 's1'
print(type(e))
f = str(2) # y will be '2'
print(type(f))
g = str(3.0) # z will be '3.0'
print(type(g)) # BOOLEAN STARTS HERE

# Boolean Values
print
(8 > 9)
print(8== 9)
print(12< 11)
# # Evaluate Values and Variables
print(bool("Hello"))
print(bool("rhy"))
''' Most Values are True
Almost any value is evaluated to True if it has some sort of content.
Any string is True, except empty strings.
Any number is True, except 0.
Any list, tuple, set, and dictionary are True, except empty ones.
'''
bool("abc")
bool(123)
bool(["apple", "cherry", "banana"])
# # Some Values are False
bool(False)
bool(None)
bool(0)
bool("")
bool(())
bool([])
bool({})
# # Functions can Return a Boolean
def myFunction() :
return True
print(myFunction())

Comments

Popular Posts