Ticker

6/recent/ticker-posts

Python Language tutorial for beginners

Boolean Values in python for beginners at home  (2021 grasp basic python online with role model)

 

Python Language tutorial for beginners




Boolean Values in Python: 

In every context or program or theory, everyone wants to know what is true and what is false.

In Python language boolean represents what is true and what is false. This boolean gives an answer when we compare any two values whether the condition is true or false.

Example: 

print(13 > 7)
print(13 == 7)
print(13 < 7)

Expected Output:

  • NOTE: There are some values that mostly happen True. Except for the empty strings, lists, tuples, and 0 in a number any strings, lists, tuples are "True".

Example: 

print(bool("abc"))
print(bool(123))
print(bool(["apple", "cherry", "banana"]))

Expected Output:



  • NOTE: There are some values that happen False. (), {}, 0, " ", [] are always "False".

Example: 

print(bool(""))
print(bool(0))
print(bool(()))
print(bool([]))
print(bool({}))

Expected Output:


Creating boolean answer by using if-else statements:

Code:

def myFunction() :
  return True

if myFunction():
  print("YES!")
else:
  print("NO!")

Expected Output:



Post Navi

Post a Comment

0 Comments