Arithmetic operations on Bools?

Answer: B. False Solution: Let's go checking the if-condition, which is (3>2) > 1 Now remember that no matter what, attack the parenthesis first. So we solve (3>2), ie, True Expression simplifies to True > 1 It's a bit of a fix now. Because how to compare a bool with int? +



works but is there any real life implementation of this?


Not very often, but it can be applied. For example, you have a list like so li = [5, 7, 3, 2, 9] You want to count how many items are >5. You could use sum(x>5 for x in li) This works by creating a bool (x>5). If True, adds 1. Else adds 0. Effectively counting Trues. +


Why guess when you can know?


United States Trends
Loading...

Something went wrong.


Something went wrong.