Introductory Programming Fall 2004 For next time: 1) finish hw01 (which we will start in class today) But don't spend more than two hours. On Tuesday we will have our first evaluation. It will be practical, in the sense that I will ask you to do things at your laptop, and you will write answers that demonstrate that you were successful. If you are keeping up, you will be able to do the evaluation. Olinux Chapter 2 ---------------- If you are not completely sick of hearing me spout off about Free Software, check out my way-too-long article from last year's Frankly Speaking: http://projects.olin.edu/newspaper/article.php?id=92 New tools 1) emacs 2) cat and more 3) grep and sed 4) mkdir and rmdir 5) variables and aliases in .bashrc 6) rm and rm -i Values ------ Three types of values (so far) >>> type(123) integer >>> type(123.7) floating-point >>> type('bob123') string What type is '123'? Variables --------- Variables are names that refer to values. The assignment statement assigns a value to a variable. >>> x = 5 When this statement is executed, it creates a variable named x and assigns the value 5 to it. >>> print x # prints the value that x refers to. >>> type(x) # prints the type of the value that x refers to. >>> x + 5 # computes the sum of 5 and the value x refers to. >>> x = 'bob' # changes x to refer to a different value Expressions ----------- An expression is a combination of operands and operators that can be evaluated to yield a value. >>> 3 + 1 # apply the addition operator to two integers >>> 3.14 + 2.178 # floating-point addition >>> 'bob' + 'olink' # string addition? Python uses the type of the operands to decide which operation to do. Variables in expressions ------------------------ A variable name, all by itself, can be an expression. >>> x = 5 >>> x 5 The value of the expression is the value the variable refers to. Another way to say the same thing is that you can SUBSTITUTE the value for the variable. x + 3 can be rewritten as 5 + 3 can be rewritten as 8 Try this: >>> x = 5 >>> y = x + 1 # this works >>> x + 1 = y # this doesn't -- why not? Assignment is a statement that gets executed, NOT a declaration of equality.