Lecture 2: October 1, 2019

Reading: §2
Due: Homework 1, due on October 10 at 11:59pm


  1. Variables
    1. What they are
    2. Variable names
    3. Variable types (int, float, string)
    4. Function type()
    5. Python keywords
  2. Variables
    1. Legal names
    2. Keywords
    3. How to pick variable names
  3. Simple assignment: variable = expression
  4. Expressions
    1. Operators +, -, *, /, //, %, **
    2. Precedence
      1. Parentheses for grouping ((, ))
      2. Exponentiation (**); associates right to left
      3. Positive, negative (unary +, -)
      4. Multiplication, division, integer division, remainder (*, /, //, %)
      5. Addition, subtraction (binary +, -)
      6. In general, operators of equal precedence are evaluated from the left to the right (associativity); exception noted above
  5. Example
    1. Compute the hypotenuse of a right triangle [hypotnoex.py]
  6. The difference between strings and integers [twoplustwo.py]
    1. Difference between ’2 + 2’, 2 + 2
  7. Type converter functions int, float, str
  8. String operators
    1. Operator +: string concatenation
    2. Operator *: repetition
  9. Input: input statement
    1. input(prompt) prints prompt, waits for user
    2. When user hits enter, it returns what was typed as a string
  10. Exceptions
    1. Division by zero [divby0.py]
    2. Typing letters when a number is expected [hypotex.py]

UC Davis sigil
Matt Bishop
Office: 2209 Watershed Sciences
Phone: +1 (530) 752-8060
Email: mabishop@ucdavis.edu
MHI 289I, Programming in Health Informatics
Version of September 30, 2019 at 10:17PM

You can also obtain a PDF version of this.

Valid HTML 4.01 Transitional Built with BBEdit Built on a Macintosh