- two kinds of programs process high level language into low level language: interpreter & compiler
- source code -> interpreter -> outputx
- source code -> compiler -> object code -> executor -> output
- program: a program is a sequence of instructions that specifies how to perform a computation.
- script: the contents stored in form of a file
- value: one of the basic units of data, like a number or string, that a program manipulates.
- type: a category of values.
- variable: a name that refers to a value.
- argument: the expression in parentheses
-
question: why display the numbers start with 0 makes it bizarre?
-
note: page 20 has many definitions
- two types of partition table: (1)MBR: Master Boot Record (2)GPT: GUID Partition Table
- flow of execution: the order in which statement are executed
- Function: a named sequence of statements that performs some useful operation. Functions may or may not take arguments and may or may not produce a result.
- function definition: a statement that creates a new function, specifying its name, parameters, and the statements it excutes.
- function object: a value created by a function definition. The name of the function is a variable that refers to a function object.
- instance: a member of set
- encapsulation: wrap a piece of code up in a function.
- generaliztion: add a parameter to a function
- interface of a function: a summary of how it is used: what are the parameters? What does the function do? And what is the return value? An interface is "clean" if it is "as simple as possible, but not simpler. (Einstein)"
- A development plan: a process for writing programs. (1) Start by writing a small program with no function definitions. (2) Once you get the program working, encapsulate it in a function and give it a name. (3) Generalize the functionn by adding appropriate parameters. (4) Repeat steps 1-3 until you have a set of working functions. Copy and paste working code to aviod retyping( and re-bugging) (5) Loot for opportunities to improve the program by refactoring. For example, if you have similar code in several places, consider facotring it into an appropriately general function.
- modulus operator: %
- boolean expressions: either true or false
- logical operators: and, or, not
- conditional execution: if
- alternative execution: else, elif
- chained conditionals: 2+ branches
- nested conditionals
- recursion
- stack diagram for recursive function. (1)n = 0, base case (2)
- infinite recursion
- keyboard input --> raw_input()
- guardian
- debuging: there are three possiblities here: (1)There is something wrong with the arguments the function is getting; a precondition is violated. (2)There is something wrong with the function; a post condition is violated. (3)These is something wrong with the return value or the way it is being used.
- Return Values
- Incremental Development
- Composition
- Boolean Functions
- More Recursion
- Leap of Faith
- Checking Types
- Debugging
- Multiple Assignment: to distinguish between an assignment operation and a statement of equality
- Updating Variables: (1)increment (2)decrement
- The while Statement
- key and values -> key-value pair (aka item)
- associative memories
- string and numbers can always be keys!!!
- keys are immutable
- Tuples can be used as keys if they contain only strings, numbers, or tuples; if a tuple contains any mutable object either directly or indirectly, it cannot be used as a key.
- list CANNOT be keys!!!!
- The _ (undersocre) in python means:
_ has 3 main conventional uses in Python:
1. To hold the result of the last executed statement in an interactive interpreter session. This precedent was set by the standard CPython interpreter, and other interpreters have followed suit
2. For translation lookup in i18n (imported from the corresponding C conventions, I believe), as in code like: raise
forms.ValidationError(_("Please enter a correct username"))
3. As a general purpose "throwaway" variable name to indicate that part of a function result is being deliberately ignored, as in code like: label, has_label, _ = text.partition(':')
The latter two purposes can conflict, so it is necessary to avoid using _ as a throwaway variable in any code block that also uses it for i18n translation (many folks prefer a double-underscore, __, as their throwaway variable for exactly this reason).
- use 'in' to check whether a value is in the list
What is difference between return
and pass
in python? Souce
Return
exits the current function or method.Pass
is a null operation and allows execution to continue at the next statement.
- Sometimes when you ask a question, you find the answer before you finish asking, then you don't need to ask a real person, you can just ask a rubber duck. It's a real thing called rubber duck debugging, you can just see the wikipedia.
- persistence: run for a long time (or all the time), keep at least some of data in permanent storage
- trasience: run for a short time, when the program ends, data vanish as well
-
If the file already exists, opening it in write mode clears out the old data and starts fresh, so be careful!
-
When the first oprand is a string, % is a format operator
-
relative path
-
absolute path, starts wtih '/'
-
dbm is a module in Python 3!
-
pipe object: an object representing a running program
-
What is pickle? pickle is a module implements serializing and de-serializing a Python object structure. "Pickling" is the process whereby a Python object hierarchy is converted into a byte stream, and "unpickling" is the inverse operation
-
%c char single character
-
%d (%i) int signed integer
-
%e (%E) float or double exponential format
-
%f float or double signed decimal
-
%g (%G) float or double use %f or %e as required
-
%o int unsigned octal value
-
%p pointer address stored in pointer
-
%s array of char sequence of characters
-
%u int unsigned decimal
-
%x (%X) int unsigned hex value
- == operator for object will check the object identity as is operator rather than object equvalence,
- Object-oriented: represents relationship between programmer-defined types and functions
- veneer: a method or function that provide a different interface to another function without doing much computation
A Counter represents a multiset.