CSC 1200 Lecture : python notes cmsc 201 (4)
Document Summary
Booleans represent one of two values: true or false. In programming you often need to know if an expression is true or false. You can evaluate any expression in python, and get one of two answers, When you compare two values, the expression is evaluated and python returns the boolean answer: Get your own python server print(10 > 9) print(10 == 9) print(10 < 9) When you run a condition in an if statement, python returns true or false: Print a message based on whether the condition is true or false: a = 200. = 33 if b > a: print("b is greater than a") else: print("b is not greater than a") The bool() function allows you to evaluate any value, and give you true or. Evaluate a string and a number: print(bool("hello")) print(bool(15)) Evaluate two variables: x = "hello" y = 15 print(bool(x)) print(bool(y)) Almost any value is evaluated to true if it has some sort of content.