Glossary

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 20

Contents

1.General Introduction................................................................................................................2
2. Variables, Statements, and Expressions...........................................................................5
4. Python Modules.........................................................................................................................8
5. Summary of Turtle Methods.................................................................................................9
7. Iteration.....................................................................................................................................10
7.8.1. The RGB color model.......................................................................................................11
7.8.2.Image Objects.....................................................................................................................12
8. Conditionals..............................................................................................................................13
9. Transforming sequences......................................................................................................14
10. Files...........................................................................................................................................16
11. Dictionaries............................................................................................................................16
Glossary
1.General Introduction
activecode
A unique interpreter environment that allows Python to be executed from within a web browser.
algorithm
A step by step list of instructions that if followed exactly will solve the problem under
consideration.
bug
An error in a program.
byte code
An intermediate language between source code and object code. Many modern languages first
compile source code into byte code and then interpret the byte code with a program called
a virtual machine.
codelens
An interactive environment that allows the user to control the step by step execution of a Python
program
comment
Information in a program that is meant for other programmers (or anyone reading the source
code) and has no effect on the execution of the program.
compile
To translate a program written in a high-level language into a low-level language all at once, in
preparation for later execution.
debugging
The process of finding and removing any of the three kinds of programming errors: *syntax
error*, *semantic error*, and *runtime error*.
exception
Another name for a runtime error.
executable
Another name for object code that is ready to be executed.
formal language
Any one of the languages that people have designed for specific purposes, such as representing
mathematical ideas or computer programs; all programming languages are formal languages.
high-level language
A programming language like Python that is designed to be easy for humans to read and write.
interpret
To execute a program in a high-level language by translating it one line at a time.
low-level language
A programming language that is designed to be easy for a computer to execute; also called
machine language or assembly language.
natural language
Any one of the languages that people speak that evolved naturally.
object code
The output of the compiler after it translates the program.
parse
To examine a program and analyze the syntactic structure.
portability
A property of a program that can run on more than one kind of computer.
print function
A function used in a program or script that causes the Python interpreter to display a value on its
output device.
problem solving
The process of formulating a problem, finding a solution, and expressing the solution.
program
A sequence of instructions that specifies to a computer actions and computations to be
performed.
programming language
A vocabulary and set of grammatical rules for instructing a computer or computing device to
perform specific tasks.
Python shell
An interactive user interface to the Python interpreter, and the user of a Python shell types
commands at the prompt (>>>), and presses the return key to send these commands immediately
to the interpreter for processing. To initiate the Python Shell, the user should open theterminal
and type “python”. Once the user presses enter, the Python Shell appears and the user can
interact with it.
runtime error
An error that does not occur until the program has started to execute but that prevents the
program from continuing.
semantic error
An error in a program that makes it do something other than what the programmer intended.
semantics
The meaning of a program.
shell mode
A mode of using Python where expressions can be typed and executed in the command prompt,
and the results are shown immediately in the command terminal window. Shell mode is initiated
by opening the terminal of your operating system and typing “python”. Press enter and the
Python Shell will appear. This is in contrast to source code. Also see the entry under Python
shell.
source code
The instructions in a program, stored in a file, in a high-level language before being compiled or
interpreted.
syntax
The structure of a program.
syntax error
An error in a program that makes it impossible to parse — and therefore impossible to interpret.
token
One of the basic elements of the syntactic structure of a program, analogous to a word in a
natural language.
2. Variables, Statements, and Expressions
assignment statement
A statement that assigns a value to a name (variable). To the left of the assignment operator, =, is
a name. To the right of the assignment token is an expression which is evaluated by the Python
interpreter and then assigned to the name. The difference between the left and right hand sides of
the assignment statement is often confusing to new programmers. In the following assignment:
n=n+1
n plays a very different role on each side of the =. On the right it is a value and makes up part of
the expression which will be evaluated by the Python interpreter before assigning it to the name
on the left.
assignment token
= is Python’s assignment token, which should not be confused with the mathematical comparison
operator using the same symbol.
boolean expression
An expression that is either true or false.
boolean value
There are exactly two boolean values: True and False. Boolean values result when a boolean
expression is evaluated by the Python interepreter. They have type bool.
class
see data type below
comment
Information in a program that is meant for other programmers (or anyone reading the source
code) and has no effect on the execution of the program.
data type
A set of values. The type of a value determines how it can be used in expressions. So far, the
types you have seen are integers (int), floating-point numbers (float), and strings (str).
decrement
Decrease by 1.
evaluate
To simplify an expression by performing the operations in order to yield a single value.
expression
A combination of operators and operands (variables and values) that represents a single result
value. Expressions are evaluated to give that result.
float
A Python data type which stores floating-point numbers. Floating-point numbers are stored
internally in two parts: a base and an exponent. When printed in the standard format, they look
like decimal numbers. Beware of rounding errors when you use floats, and remember that they
are only approximate values.
increment
Both as a noun and as a verb, increment means to increase by 1.
initialization (of a variable)
To initialize a variable is to give it an initial value. Since in Python variables don’t exist until
they are assigned values, they are initialized when they are created. In other programming
languages this is not the case, and variables can be created without being initialized, in which
case they have either default or garbage values.
int
A Python data type that holds positive and negative whole numbers.
integer division
An operation that divides one integer by another and yields an integer. Integer division yields
only the whole number of times that the numerator is divisible by the denominator and discards
any remainder.
keyword
A reserved word that is used by the compiler to parse program; you cannot use keywords
like if, def, and while as variable names.
literal
A number or string that is written directly in a program. Sometimes these are also referred to as
literal values, or just values, but be careful not to confuse a literal value as written in a program
with an internal value maintained by the Python interpreter during execution of a program.
logical operator
One of the operators that combines boolean expressions: and, or, and not.
modulus operator
An operator, denoted with a percent sign ( %), that works on integers and yields the remainder
when one number is divided by another.
object
Also known as a data object (or data value). The fundamental things that programs are designed
to manipulate (or that programmers ask to do things for them).
operand
One of the values on which an operator operates.
operator
A special symbol that represents a simple computation like addition, multiplication, or string
concatenation.
prompt string
Used during interactive input to provide the use with hints as to what type of value to enter.
reference diagram
A picture showing a variable with an arrow pointing to the value (object) that the variable refers
to. See also state snapshot.
rules of precedence
The set of rules governing the order in which expressions involving multiple operators and
operands are evaluated.
state snapshot
A graphical representation of a set of variables and the values to which they refer, taken at a
particular instant during the program’s execution.
statement
An instruction that the Python interpreter can execute. So far we have only seen the assignment
statement, but we will soon meet the import statement and the for statement.
str
A Python data type that holds a string of characters.
type conversion function
A function that can convert a data value from one type to another.
value
A number or string (or other things to be named later) that can be stored in a variable or
computed in an expression.
variable
A name that refers to a value.
variable name
A name given to a variable. Variable names in Python consist of a sequence of letters (a..z, A..Z,
and _) and digits (0..9) that begins with a letter. In best programming practice, variable names
should be chosen so that they describe their use in the program, making the program self
documenting.
4. Python Modules
deterministic
A process that is repeatable and predictable.
documentation
A place where you can go to get detailed information about aspects of your programming
language.
module
A file containing Python definitions and statements intended for use in other Python programs.
The contents of a module are made available to the other program by using the import statement.
namespace
A naming system for making names unique, to avoid duplication and confusion. Within a
namespace, no two names can be the same.
pseudo-random number
A number that is not genuinely random but is instead created algorithmically.
random number
A number that is generated in such a way as to exhibit statistical randomness.
random number generator
A function that will provide you with random numbers, usually between 0 and 1.
standard library
A collection of modules that are part of the normal installation of Python.
5. Summary of Turtle Methods
Method Parameters Description

Turtle None Creates and returns a new turtle object

forward distance Moves the turtle forward

backwar distance Moves the turle backward


d

right angle Turns the turtle clockwise

left angle Turns the turtle counter clockwise

up None Picks up the turtles tail

down None Puts down the turtles tail

color color name Changes the color of the turtle’s tail

fillcolor color name Changes the color of the turtle will use to fill a polygon

heading None Returns the current heading

position None Returns the current position

goto x,y Move the turtle to position x,y

begin_fill None Remember the starting point for a filled polygon

end_fill None Close the polygon and fill with the current fill color

dot None Leave a dot at the current position

stamp None Leaves an impression of a turtle shape at the current


location

shape shapename Should be ‘arrow’, ‘triangle’, ‘classic’, ‘turtle’, ‘circle’, or


‘square’

speed integer 0 = no animation, fastest; 1 = slowest; 10 = very fast

Turtle: https://docs.python.org/3/library/turtle.html
7. Iteration
Control Flow
Also known as the flow of execution, the order in which a program executes. By default, the
control flow is *sequential*.
for loop traversal (for)
Traversing a string or a list means accessing each character in the string or item in the
list, one at a time. For example, the following for loop:

for ix in 'Example':

...

executes the body of the loop 7 times with different values of ix each time.
ex A variable or value used to select a member of an ordered collection, such as a
character from a string, or an element from a list.
p body The loop body contains the statements of the program that will be iterate through
upon each loop. The loop body is always indented.
pattern
A sequence of statements, or a style of coding something that has general applicability in a
number of different situations. Part of becoming a mature programmer is to learn and establish
the patterns and algorithms that form your toolkit.
range
A function that produces a list of numbers. For example, range(5), produces a list of five
numbers, starting with 0, [0, 1, 2, 3, 4].
sequential flow
The execution of a program from top to bottom, one statement at a time
terminating condition
A condition which stops an interation from continuing
traverse
To iterate through the elements of a collection, performing a similar operation on each.
7.8.1. The RGB color model

Color Red Green Blue

Red 255 0 0

Green 0 255 0

Blue 0 0 255

White 255 255 255

Black 0 0 0

Yellow 255 255 0

Magenta 255 0 255

Method
Name Example Explanation

Pixel(r,g,b) Pixel(20,100, Create a new pixel with 20 red, 100


50) green, and 50 blue.

getRed() r= Return the red component


p.getRed() intensity.

getGreen() r= Return the green component


p.getGreen() intensity.

getBlue() r= Return the blue component


p.getBlue() intensity.

setRed() p.setRed(100 Set the red component intensity to


) 100.

setGreen() p.setGreen(4 Set the green component intensity


5) to 45.

setBlue() p.setBlue(15 Set the blue component intensity to


6) 156.
7.8.2.Image Objects

Method Name Example Explanation

Image(filenam img = Create an Image


e) image.Image(“cy.png”) object from the file
cy.png.

EmptyImage() img = Create an Image


image.EmptyImage(100, object that has all
200) “White” pixels

getWidth() w = img.getWidth() Return the width of


the image in pixels.

getHeight() h = img.getHeight() Return the height of


the image in pixels.

getPixel(col,ro p = img.getPixel(35,86) Return the pixel at


w) column 35, row 86.

setPixel(col,ro img.setPixel(100,50,mp) Set the pixel at


w,p) column 100, row 50
to be mp.

Level Category Operators

7(high) exponent **

6 multiplication *,/,//,%

5 addition +,-

4 relational ==,!=,<=,>=,>,<

3 logical not

2 logical and

1(low) logical or
8. Conditionals
block
A group of consecutive statements with the same indentation.
body
The block of statements in a compound statement that follows the header.
boolean values
A value that is either True or False. True and False must be capitalized to be considered Boolean.
branch
One of the possible paths of the flow of execution determined by conditional execution.
chained conditional
A conditional branch with more than two possible flows of execution. In Python chained
conditionals are written with if ... elif ... else statements.
comparison operator
One of the operators that compares two values: ==, !=, >, <, >=, and <=.
condition
The boolean expression in a conditional statement that determines which branch is executed.
conditional statement
A statement that controls the flow of execution depending on some condition. In Python the
keywords if, elif, and else are used for conditional statements.
logical operators
“and”, “or” and “not” are logical operators used to evaluate expressions. Their semantic meaning
is similar to their English meaning.
nesting
One program structure within another, such as a conditional statement inside a branch of another
conditional statement.
unary selection
A selection statement in which there is only an “if” statement and the “else” statement is omitted
entirely. In an unary selection, the statements are only executed if the condition evaluates to true,
otherwise the program continues to the body following the if statement.
9. Transforming sequences
for loop traversal (for)

Traversing a string or a list means accessing each character in


the string or item in the list, one at a time. For example, the
following for loop:

for ix in 'Example':
...
executes the body of the loop 7 times with different values
of ix each time.
range

A function that produces a list of numbers. For


example, range(5), produces a list of five numbers, starting with
0, [0, 1, 2, 3, 4].
pattern

A sequence of statements, or a style of coding something that


has general applicability in a number of different situations. Part
of becoming a mature programmer is to learn and establish the
patterns and algorithms that form your toolkit.
index

A variable or value used to select a member of an ordered


collection, such as a character from a string, or an element from
a list.
traverse

To iterate through the elements of a collection, performing a


similar operation on each.
accumulator pattern

A pattern where the program initializes an accumulator variable


and then changes it during each iteration, accumulating a final
result.
Method Parameters Result Description

append item mutator Adds a new item to the end of a list

insert position, item mutator Inserts a new item at the position given

pop none hybrid Removes and returns the last item

pop position hybrid Removes and returns the item at position

sort none mutator Modifies a list to be sorted

reverse none mutator Modifies a list to be in reverse order

index item return idx Returns the position of first occurrence of


item

count item return ct Returns the number of occurrences of item

remove item mutator Removes the first occurrence of item

Metho Paramete
d rs Description

upper none Returns a string in all uppercase

lower none Returns a string in all lowercase

count item Returns the number of occurrences of item

index item Returns the leftmost index where the substring item is found
and causes a runtime error if item is not found

strip none Returns a string with the leading and trailing whitespace
removed

replac old, new Replaces all occurrences of old substring with new
e

forma substituti Involved! See String Format Method, below


t ons
10. Files
open
You must open a file before you can read its contents.
close
When you are done with a file, you should close it.
read
Will read the entire contents of a file as a string. This is often used in an assignment statement so
that a variable can reference the contents of the file.
readline
Will read a single line from the file, up to and including the first instance of the newline
character.
readlines
Will read the entire contents of a file into a list where each line of the file is a string and is an
element in the list.
write
Will add characters to the end of a file that has been opened for writing.

Method Name Use Explanation

open open(filename,'r') Open a file called filename and use it for


reading. This will return a reference to a file
object.

open open(filename,'w') Open a file called filename and use it for


writing. This will also return a reference to a file
object.

close filevariable.close() File use is complete.

write filevar.write(astring Add a string to the end of the file. filevar must
)
refer to a file that has been opened for writing.

read(n) filevar.read() Read and return a string of n characters, or the


entire file as a single string if n is not provided.

readline(n) filevar.readline() Read and return the next line of the file with all
text up to and including the newline character.
If n is provided as a parameter, then
only n characters will be returned if the line is
longer than n. Note the parameter n is not
supported in the browser version of Python, and
in fact is rarely used in practice, you can safely
ignore it.

readlines(n) filevar.readlines() Returns a list of strings, each representing a


Method Name Use Explanation

single line of the file. If n is not provided then


all lines of the file are returned. If n is provided
then n characters are read but n is rounded up
so that an entire line is
returned. Note Like readline readlines ignores
the parameter n in the browser.
11. Dictionaries
dictionary
A collection of key-value pairs that maps from keys to values. The keys can be any immutable
type, and the values can be any type.
key
A data item that is mapped to a value in a dictionary. Keys are used to look up values in a
dictionary.
value
The value that is associated with each key in a dictionary.
key-value pair
One of the pairs of items in a dictionary. Values are looked up in a dictionary by key.
mapping type
A mapping type is a data type comprised of a collection of keys and associated values. Python’s
only built-in mapping type is the dictionary. Dictionaries implement the associative
array abstract data type.

Method Parameters Description

keys none Returns a view of the keys in the dictionary

values none Returns a view of the values in the dictionary

items none Returns a view of the key-value pairs in the dictionary

get key Returns the value associated with key; None otherwise

get key,alt Returns the value associated with key; alt otherwise

You might also like