15-110: Fall 2010
Class Notes:  Getting Started with Python (Week 2) 



Running  Python

                Show the class how to run Python and IDLE.

                Ask students to download both.

 

Expressions  & Operators

                Basic operators

                        Addition, subtraction, multiplication, exponentiation, division, mod

Other operators: +=, -=, *= 

               

Binary operators

                         <    >   <=   >=  ==  !=   <>
               

Assignment operator

 =

               

Order of evaluation

                        2 * 4 + 3

               

Using parenthesis

                        2 * ( 4 + 3)

               

Types

                Integer

                Float

                Boolean

                Sequence of characters (Strings)

                                Using single quotes (‘string‘)

                                Using double quotes (“string“)

                                Discuss basic slicing as a way to extract chars from the string

                Mixed types expressions and their evaluation
 

 

Variables

                Identifiers rules

                Using variables to store data
 

 

Comments

                How to write comments in Python

 

Console Input & Output

                print()

                                Escape sequences

                                String formatting (see strings_format.py)

                raw_input()

                input()

                 

Functions

                Built-in Python functions

                                abs(x),  max(x,y),  min(x,y),  round(x)

                                
chr(i),  ord(char)                       

                                
eval(str), type(x)

                                float(x),  int(x),  str(x)                              

                                len(str)

                                math functions: math.pi, math.sqrt, math.sin, math.cos, etc.

                Other Odds'n'Ends (from some problems at the end of ch1):

                                (from #10):  meaning of _ (underscore)

                                (from #15) behavior of negative #’s in mod (%) operator

                                (from #18) chained operators (like 2 < x < 8)

                                (from #19) int vs long

               

                Creating functions (none of these topics are covered in Chapter 1)

                                With/without parameters

                                calling functions

                                scope of parameters and variables

 

READINGS

                Chapter 1 + pp. 26- 29

 

SUGGESTED EXERCISES FROM THE TEXTBOOK (for students to do)

                1, 8, 10, 13, 18, 28, 29

 

CLASS ACTIVITIES            

There are some good questions in the exercises at the end of Chapter 1.

                3, 10, 11, 12, 14, 15, 19