Class Notes (836,278)
CSCA08H3 (75)
Lecture

# Boolean

3 Pages
195 Views

Department
Computer Science
Course
CSCA08H3
Professor
Kathy Fellowes
Semester
Fall

Description
CSCA08 – Introduction to Computer Programming Boolean Representation in Python References: • http://www.youtube.com/watch?v=Ex1mGJ51ga0 • http://www.youtube.com/watch?v=sBtmqTFc73Q Atrue/false value is called a Boolean type, named after George BooCheck in Python: philosopher and logician of the early 19th century. False == 0 True == 1 In Python we denote the Boolean type by bool. The bool type in PytFalse < True only two values: True and False. There are many different operators in Python that evaluate to True or False (note the capital letters). For each of the following expressions that use conditional operators, write down the result that they evaluate to: 3 < 4 3 > 8 8 > 3 3.5 >= 3.5 7 == 7 # Why not just one equals sign?\\ x = 7 y = 7.0 x == y 3 != 4 False is stored internally as 0, and True as 1. Even though True is 1, when checking boolean condition, Python treats any non-zero number as True. if 0: if 1: Examples to try out: if 9.2423: print print print 'yay' 'yay' 'yay' num = 6 if num == 10 or 20 or 30: What does this do? print 'yay' else: print 'no way' CSCA08 – Fall 2010 Booleans and If-Statements in Python Page 1 of 3 Python treats any numeric value not equal to 0 as True. This means that: False < True if 10.5: print "10.5 is true!" prints out 10.5 is true! If-Statements in Python In everyday life, we often make decisions based on the current conditions. If the weather is warm, I wear shorts. Otherwise, I wear pants. The same conditional process appears when writing code. To handle these situations we use an if statement. Form for writing an if-statement: if condition_1: statements_1 elif condition_2: statements_2
More Less

Related notes for CSCA08H3
Me

OR

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Join to view

OR

By registering, I agree to the Terms and Privacy Policies
Just a few more details

So we can recommend you notes for your school.

Get notes from the top students in your class.

Request Course
Submit