1/75
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
Low-level versus high-level
Whether we program using instructions and data objects at the level of the machine (ie. move 64 bits of data from this location to this location) or whether we program using more abstract operations (ie. pop up a menu on the screen) that have been provided by the language designer.
General versus targeted to an application domain
Whether the primitive operations of the programming language are widely applicable or are fine-tuned to a domain.
Interpreted versus Compiled
Whether the sequence of instructions written by the programmer is executed directly, or whether it is first converted into a sequence of machine-level primitive operations.
Source Code
A sequence of instructions written by the programmer
Machine Code
Code that can be directly interpreted by the computer hardware
Advantages with Interpreted languages
It is often easier to debug prgrams
Advantages to compiled languages
They run more quickly and use less space
What is python good for?
Can be used to build any kind of program that does not need direct access to the computer's hardware.
Relatively simple and easy to learn.
Runtime feedback that is helpful to novice programmers.
Freely available libraries that interface to python and provide extended functionality.
What are the downfalls of python?
Weak static semantic checking. This makes it not optimal for programs that have high reliability constraints or are built and maintained by many people over a period of time.
Python Program
A sequence of definitions and commands
Python Script
Synonymous to Python Program
Shell
A window is usually associated with one of these.
This is where the definitions from the program are evaluated and the commands are executed by a python interpreter.
A new one of these is usually created whenever the execution of a program begins.
Command
Also known as a statement.
Instructs the interpreter to do something.
Objets
Core things that python programs manipulate.
Every one of these has a type
Type
Defines the kinds of things that programs can do with that object.
Scalar Objects
Objects that are indivisible.
They are like the atoms of the language.
Non-scalar objects
Things that have internal structure, such as strings.
Literals
notation for representing a fixed value in source code
Four Types of Scalar Objects in Python
1) int
2) float
3) bool
4) None
int
Represents integers.
Written in the way that we usually denote integers, which is with numbers.
float
Represents real numbers and always uses a decimal point.
Floating point numbers
There is no fixed number of digits before/after the decimal point. For instance, 1600.0, you can have as many zeroes as you want after the decimal point, or you can denote this number as 1.6e3, where the decimal point is farther to the left than the previous example.
bool
Used to represent boolean values, which are true or false
None
A type with a single value.
Value of the expression
When objects and operators are combined to form expressions, each of which evaluates to an object of some type. The object of some type is what this term means.
Example of a value
The expression 3+2 denotes the object 5 of type int
== operator
Whether two expressions evaluate to the same value
!= operator
Whether two expressions evaluate to different values
Shell Prompt
>>>
The interpreter is expecting the user to type some python code into the shell.
Python function--type
This can be used to find out the type of an object
Integer Division
i//j
It ignores the remainder and only returns the quotient
Ex: 6//4=1, not 1.5
Remainder
i%j
pronounced "i mod j" which is short for "i modulo j"
Exponent
i**j
If both are a type of int, this results in an int. If one is a type of float, the answer will be a float.
Primitive operators on type bool
and
or
not
bool a and b
is true if both a and b are true, false otherwise
bool a or b
is true if at least one of a or b is true, and false otherwise
bool not a
is true if a is false, and false if a is true
Variables
Provide a way to associate names with objects.
These are just names, they are nothing more than that.
Binding
The substitution of a real value for a variable/replacing the number with a machine address after the program is compiled
Assignment
Associates the name to the left of the = symbol with the object denoted by the expression to the right of the = symbol.
An object and names
Can have one, more than one, or no names associated to it.
How to name a variable in python
They can contain uppercase and lowercase letters, _, and digits, however they cannot start with a digit.
Reserved words
These are also known as keywords, and they have built-in meanings and cannot be used as variable names.
Examples of Reserved Words
and
as
assert
break
class
continue
def
del
elif
else
except
False
finally
for
from
global
if
import
in
is
lambda
nonlocal
None
not
or
pass
raise
return
True
try
while with
yield
These are considered different words in python
julie and Julie
Comments
Text following the pound symbol in python that is not integrated into the code, but gives the programmer insight into what the variables are doing and the functions of the program
Integrated Development Environment (IDE)
Provides a developer with a way to create a program, run the program, and debug the program all within one application.
IDLE
Part of the standard python installation package. It is an example of an IDE.
Popular IDE's
Anaconda and Canopy
What do all python IDE's provide?
1) A text editor with syntax highlighting, auto completion, and smart indentation
2) A shell with syntax highlighting
3) An integrated debugger
Straight Line programs
Programs that execute one statement after another in the order in which they appear, and stop when they run out of statements.
These programs are typically pretty boring.
Branching Programs
An instruction that tells a computer to begin executing a different part of a program rather than executing statements one-by-one
3 parts of a conditional statement
1) a test ie., an expression that evaluates to either True or False
2) a block of code that is executed if the test evaluates to True
3) An optional block of code that is executed if the test evaluates to false.
Form of a conditional statement in python
if Boolean expression:
block of code
else:
block of code
Advantage of indentation
Ensures that the visual structure of a program is an accurate representation of the semantic structure of that program.
Nested
When one block of code contains another block of code
elif
else if
Compound Boolean Expression
A combination of two or more Boolean expressions using logical operators
Constant Time
A program for which the maximum running time is bounded by the length of the program.
There exists a constant, k, such that the program is guaranteed to take no more than k steps to run.
The running time does not grow with the size of the input to the program.
These programs are pretty limited in what they can do.
Computational Complexity
The study of the intrinsic difficulty of problems
str
string
How are strings written?
With single or double quotes.
Overloaded
When something has different meanings, depending upon the types of the objects to which it is applied.
Repetition Operator
makes multiple copies of a string and joins them together
Type Checking
Turns careless mistakes into errors that stop execution, rather than errors that lead programs to behave in mysterious ways.
Length of a string
You can find the length by using the len function.
Example: value of len('abc') is 3
Indexing
Can be used to extract individual characters from a string. All indexing in python is zero-based.
Example: 'abc'[0] will spit out the string 'a'
Negative numbers in indexing then start at the end of the string
Example: 'abc'[-1] will spit out the string 'c'
Slicing
Used to extract substrings of arbitrary length.
Example: s is a string
s[start:end] denotes the substring of s that starts at index start and ends at index end -1
Example: 'abc'[1:3] will spit out 'bc'
Input
Takes a string as an argument and displays it as a prompt in the shell.
It waits for the user to type something, followed by hitting the enter key. The line typed by the user is treated as a string and becomes the value returned by the function.
Type Conversions (Type Casts)
We use the name of a type to convert values to that type.
Example: int('3')*4 is 12.
When a float is converted to an int, the number is truncated rather than rounded, so int(3.9) is the int 3
Unicode Standard
Character coding system designed to support the digital processing and display of the written texts of all languages.
More than 120,000 different characters.
How to tell python which encoding to use
# -- coding: encoding name --
Iteration
Something we use when we want a program to do the same thing many times
Looping
A generic iteration mechanism. It begins with a test, and if the test evaluates to true, the program executes the loop body once, and then goes back to reevaluate the test. It continues to do this until the test evaluates false, where then the control is to the code after the iteration statement.
Hand simulation
Attempting to solve code on paper instead of through a program, such as python. This is useful in understanding how a program behaves.
Break statement
Terminates a loop in which it is contained, and transfers control to the code immediately following the loop.
If this statement is inside a nested loop, the break will terminate the inner loop.