Zusammenfassung der Ressource
Think Python
- Green Tea Press
Chapter 1
- 1.1
- Interpreters and Compilers
- These are both ways of
translating High level
languages into lower level
ones
- A compiler checks and
translates the whole of
the source code before
running the program
- An interpreter translates
and executes the souce
code a chunk at a time. It
translates a line then runs
it
- Example
- Python is an iterpreted
language because it is
executed by an interpreter
- There are two ways to use this interpreter: Interactive mode and
Script mode. Interactive mode is on the initail window marked
by >>> which is a direct way to execute code >>> 2+2 and python will
respond on the next line with >>> 4 . Script mode needs a new
window opened and is used for larger and more demanding
scripts like a full game or etcha-sketch
- High Level and low level
programs
- Higher level programs
are able to work on a
variety of computers
with very little
tweaking
- Python is a high level
program so the
computer has to go
through it before it runs.
Other examples are Java
and C++
- Low level programs
don't need
translating
- 1.2
- What is a program?
- A program is a set of
instructions that says how to
perform a computation
- The details vary per specific language but same basic
principals remain. These are what a program is translated
into, it doesn't matter how complicated it may be
- Input: Gathering data from a keyboard,
mic or other device
- Output: Displaying the data on a screen
or other device
- Math: Simple addition,
subtraction etc
- Conditional execution: Looking for the
IFs and BUTs within a program and
following them
- Repetition: Repeating an action.
sometimes with slight variations
- 1.3
- Debugging
- Debugging is the process of finding
and correcting errors in you program
- There are 3 types of error
- Syntax Error
- A syntax error is an error with the rules
of a structure: (2+2) is legal, but 2+2) is
not because brackets always come in
pairs
- Runtime Error
- Runtime error is an
error that occurs after
the program has
started running
- Semantic Error
- A semantic error is not a problem with
how you composed the program's
structure it is a problem with what you
wanted the program to do: so you
wanted to print "Hello" but you typed
print "Helo" instead that would be a
semantic error
- 1.4
- Language types
- Formal
- These were created to
express a point in a clear and
easily understood way
- Examples of this
are mathematical
notation and
chemical short
hand
- Maths has basic
syntax rules: 2+2 = 4 is
correct but 3+=4(0 isn't
- Chemical short hand also has basic
syntax rules: CO is the short hand for
carbon monoxide but Zz doesn't work
as there is no element with the short
hand of Zz
- Natural
- These are languages like
English, German and
French, they have evolved
over time, they were NOT
created over night or by
one specific person
- 1.5
- The first program
- The traditional first
program you should write
is, in python: print "Hello,
World" , this is a print
statement meaning it will
show Hello, World on the
screen. the " in the program
defines what will be
displayed and the print is
the output method
- 1.6
- Treating the computer right
- Many people treat a computer as though
it was a real person, getting angry at it
when it points out the smallest fault and
viewing it as a teammate when it all
seems to be going well.
- The best way to view a computer is to see it as a fellow student that
has certain strengths and weaknesses: it is efficient, fast and hard
working but it is pedantic and narrow minded. try to use the
advantages and work around the weaknesses to get the best from
your computer