Programming with Python

⌘K
  1. Home
  2. Docs
  3. Programming with Python
  4. Introduction to Python
  5. Values and Types
  6. Boolean Data Type

Boolean Data Type

  • The Boolean data type is either True or False
  • In python, Boolean variables are defined by True and False keywords
  • In programming, one often need to know if an expression is True of False
  • When two values are compared, the expression is evaluated and python returns Boolean answer

Example,

>>> print(10>9)
True
  • 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(1)
True
>>> bool(0)
False

Loading

Views: 4

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments