PYTHON LECTURE NOTES 1/14/08
PYTHON LECTURE NOTES 1/14/08
Shell windows vs. editing windows
Variables
We can take input from a user and store it in a variable.
A variable is a name that we set aside as a way to refer to a certain quantity or object.
We make assignment statements:
name = “Brian L. Walter”
I’m assigning a value (“Brian L. Walter”) to a variable (name).
This command directs Python to set aside a memory location for the value, which we can refer to by the variable name.
Variables are useful:
They sometimes save some typing.
They can represent user input, which we don’t know in advance.
They can change as the program runs – they’re dynamic.
They can make programs easier to read, if variable names are chosen well.
E.g., user_input is a better name for a variable that holds some user input than x or ShardsOfBrokenGlass.
Legal variable names: you can use numbers, letters, and _s; you can’t start with a number, and it’s bad form to start with an _.
There are some reserved words – words that have special meaning to the Python interpreter – like print, if, else, etc. We can’t use those words as variable names.
Sample program using variables: firstvarexample.py
Bugs
Syntax errors vs. logic errors:
Syntax errors occur when commands are not well-formed. Syntax errors keep a program from running at all.
Logic errors occur when the program doesn’t do what you meant it to do. These can be harder to catch, since the program will run and may not even produce an error message!
Testing is how we find logic errors in programs. We need to test thoroughly!
Types
Examples of types: int (integer), float (decimal #), str (string)
We can convert from one type to another using the commands int, float, and str (see adding10.py).
READING ASSIGNMENT FOR WEDNESDAY
Finish Chapter 2
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- setting up python 3 4 numpy and matplotlib on your own
- stanford university
- python for kids lesson plan no starch press
- python lecture notes 1 14 08
- syllabus for python section of course
- lab assignment 4 commands and command lines
- python part i set up
- anaconda for python installation guide
- python murray state information systems
Related searches
- strategic management lecture notes pdf
- financial management lecture notes pdf
- business management lecture notes pdf
- organic chemistry lecture notes pdf
- corporate finance lecture notes pdf
- philosophy of education lecture notes slideshare
- business administration lecture notes pdf
- advanced microeconomics lecture notes pdf
- microeconomics lecture notes pdf
- marketing lecture notes pdf
- lecture notes in microeconomic theory
- mathematical logic lecture notes pdf