Chapter 2 Introduction to Python
objects, operators, expressions, values
Objects and operators can be combined to form expressions, each of which evaluates to an object of some type. The value of the expression.
+, -, *, //, /, %, **
are arithmetic operators
machine code
are instructions written in binary or hexadecimal and is code that the computer can respond directly to.
floating point numbers
are numbers represented as such, 3.0, 4.5, 6.6
non-scalar
are objects that have internal structure
scalar
are objects that indivisible
repetition operators
are operators which take a string and multiply them. 2 * John = johnjohn
straight-line programs
are programs that execute one statement after another in the order in which they appear, and stop when they run out of statements
objects
are the core things that is manipulated
keyword list
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
and, or, not
boolean operators
type checking
checks the type on an object
concatenation
combines 2 strings together
>, >=, ==, !=, <, <=
comparison operators
branching
contain at least one conditional statement which can reduce the length of runtime of a program but not increase the length of runtime.
type
defines the kinds of things that programs can do with an object
function: len()
determines the length of a string
compound boolean statement
evaluates two or more expressions in the conditional
conditional
has 3 parts: a test which evaluates an expression to either true or false. a block of code that is executed if the test evaluates to true an optional block of code that is executed if the test evaluates to false
reserved words / keywords
have bult-in meanings and cannot be used as a variable
conditional statement construct
if boolean statement: block of code else: block fo code
command / statement
instructs the interpreter to do something
Python Scalar Objects
int, float, bool, none
types
int, str, float
interpreted vs. compiled
interpreted programs is executed directly are easier to debug because the error messages are correlated to the source code, while compiled programs are first converted into a sequence of machine-level primitive operations, use less space, and run more quickly.
nested
is a conditional statement, within another conditional statement(s). The inner most is evaluated first
Python
is a general-purpose programming language that can be used effectively to build almost any kind of program that does not need direct access to the computer's hardware. It is not optimal for programs that have high reliability constraints, because of weak static semantic checking, or that are built and maintained by many people or over a long period of time. It is a simple language to learn. It is designed to be interpreted, it can provide the kind of runtime feedback that is especially helpful for new programmers. It has a large number of libraries that interface with Python.
low-level language
is a language that we program instructions and data objects at the level of the machine
high-level language
is a language using more abstract operations that have been provided by the language designer
program / script
is a sequence of definitions and commands
assignment
is a statement which associates the name to the left of the = symbol with the objet denoted by the expression to the right of the =.
integrated development environment (IDE)
is a text editor for writing code in.
variables
is a way to associate a name with an object
looping
is a way to iterate. it begins with a test, if it evaluates true, then the program executes a loop, and reevaluates the test. this is repeated until the test evaluates false
indentation
is semantically meaningful. Requires 4 spaces
constant time
is the maximum running time bounded by the length of the program is said to run
expressions
is the result of combining objects and operators
value
is the result of combining objects and operators
shell prompt
is the symbol >>>
type conversions / type casts
is used to convert one type of an object to another type
function: type()
is used to determine the type of an object
slicing: string[start:stop:step]
is used to extract substrings of arbitrary length
function: input()
is used to get input directly from a user
hand-simulating
is using paper and pencil to simulate the code
variable names
it's just a name, nothing more
PEMDAS
order of operations: Parentheses, Exponents, Multiplication, Division, Addition, Subtraction
targeted programming language
refers to primitive operations are targeted or fine-tuned to a specific domain
general programming language
refers to whether the primitive operations are widely applicable
source code
sequence of instructions written by a programmer
overloaded
some operators have different meanings depending upon the types of the objects to which it is applied
binds
takes a name and connects it to an object
break
terminates the loop in which it is contained
shell
the location where definitions are evaluated and the commands are executed by the interpreter.
computation complexity
the study of the intrinsic difficulty of problems
variable name style
they can be upper or lower case, have digits and a special character _. Names are case sensitive, must not start with a digit. See the Python Style Guide for more information
comments
used to enhance readability and inform the programmers later what the intentions of the code were.
indexing: string[x]
used to extract individual characters from a string
function: print()
used to print something as output
operators
when combined with operators form expressions
iteration
when you want the code to the same thing over and over again
function: while statement
while (expression != True): block of code optional counter statement