CS 1110 Concepts and Definitions

Learning a new language is always jargon heavy. Below, we present several definitions and programming concepts that you may see throughout the course. Many of these are specific to Python, but some are more general computer science concepts.

[a] [b] [c] [d] [e] [f] [g] [h] [i] [k] [l] [m] [n] [o] [p] [r] [s] [t] [u] [v] [w] [y]


a

accumulator

An accumulator is a variable in a for-loop that stores information computed by for-loop, and will be still available when the for-loop is complete. For example, in the code

    total = 0
    for x in range(5):
         total = total + x

the variable total is an accumulator.

application

An application is another name for a script.

argument

An argument is an expression that occurs within the parentheses of a method call. The following call has two arguments: x+y and y+w:

    min(x+y, y+w)

As a general rule, the number of arguments should equal the number of parameters that are called, except when using default arguments.

assert statement

An assert statement is a statement in Python used to enforce an assertion. It has one of the following forms:

    assert <bool>
    assert <bool>, <message>

In both cases, Python evaluates the boolean expression. If the expression is True, nothing happens. If it is False Python will raise an exception with the (optional) provided message.

assertion

An assertion is a true-false statement about the variables in a program at a particular part of the code. A precondition is an example of an assertion. Assertions are not the same as assert statements, as sometimes they are nothing more than comments in the code.

assignment statement

An assignment statement is a statement with the following form:

    <variable> = <expression>

If the variable does not yet exist, the statement creates the variable and stores the given value inside it. If the variable does exist, then it replaces the old value with the one provided.

attribute

An attribute is a variable belonging to either an object or a class. To reference a field, it must be preceded either by a variable containing the object name (for an object attribute) or the class name (for a class attribute). For example, to reference the attribute x inside of an Point object stored in the variable p, we use p.x.


b

basic type

A basic type is any type that has a corresponding literal. Basic types are fully integrated into Python (they do not require an import statement to use) and are not mutable. In Python, the basic types are int, float, bool, complex, and str.

bool

A bool or boolean is a basic type whose values are True and False.

bottom-up rule

The bottom-up rule is a rule that, when looking for or a method or attribute in an object, you first check the object folder, and then (if not found) start from the bottom class folder and work upward. This rule ensures that an overriding method will be called (if present) rather than an inherited one.

bug

A bug is an error in a program.


c

call frame

A call frame is an area of memory created whenever a function is called. The call frame contains the following:

The call frame changes over time as the function executes, adding, changing, or deleting variables.

call stack

A call stack is the area of memory containing all active call frames. The call frames are arranged top to bottom with the most recent call on the bottom of the stack. A call frame may not be erased until all call frames below it are erased.

cast

A cast is an operation that converts a value from one type to another. For example, the cast float(5+6) converts the value of the expression, which is 11, to float format.

A widening cast converts from less information to more information and can be done implicitly. A narrowing cast must be doneexplicitly, because it may lose information or may be illegal. See narrower type for more information.

class

In Python 3, class and type are synonyms. However, in this course we will use the term class type to refer to a user-defined type that is not built into Python. The values of a class are called objects.

class attribute

A class attribute is an attribute that is stored in the class folder, not the object folder. Changes to a class attribute affect all instances of that class.

class definition

A class definition is the code that creates a user-defined type. It starts with the keyword class and specifies the format of objects or instances of the class. It also defines the methods and attributes that go in each object.

class expression

A class expression is another name for a constructor call.

class folder

The class folder is a special folder in the heap that stores any methods or class attributes that are shared by all instances of that class.

class invariant

The class invariant is a collection of meanings and constraints on the attributes of a class that describe the valid values for these attributes before and after each method is called. The class invariant should appear as part of the class specification.

The initializer should set the attributes so that the invariant is true. Each method body can assume that the class invariant is true, and should restore the class invariant (if necessary) before it terminates.

class method

A class method is a method that is declared with decorator @classmethod. All class methods have cls as their first parameter instead of self. Class methods are called with the class name before the method, and do not require the class to have any instances. Class methods are often used as an alternative to constructors.

class specification

A class specification is description of the purpose of a class and how to use it. A class specification typically describes what entity the class is supposed to represent. Class specifications are often written using docstrings and include the class invariant.

command shell

The command shell is an OS-specific application that responds to text commands. On Windows it is called the PowerShell. On MacOS (and most Linux systems), it is called the Terminal.

comment

A comment is a line of code that is ignored by Python and only serves as a note to the programmer. Most comments start with a #. We sometimes refer to docstrings as comments. However, these are not actually ignored, since they are used by the help() function.

complex

A complex is a basic type whose include imaginary numbers. Imaginary numbers in Python are represented by the symbol j after an float. So 1j is the square root of -1.

component

A component of a class is an attribute or method that is declared in the class or is inherited from the superclass.

conditional expression

A conditional expression is an expression with the following form:

    <expr1> if <bool> else <expr2>

To evaluate this expression, Python first evaluates the boolean expression <bool>. If the boolean is true, Python uses the value of <expr1> as the value of the conditional expression. Otherwise, Python uses the value of <expr2> as the value of the conditional expression).

conditional statement

A conditional statement is a statement of the form

    if <bool>:
        <statements>

Python executes this statement as follows. If the boolean expression is True, if executes the statements underneath. Otherwise it skips over them.

An alternate form of a conditional is as follows:

    if <bool>:
        <statements>
    else:
        <statements>

This form is executed as follows. If the boolean expression is True, it executes the statements underneath the if. Otherwise it executes the statements underneath the else.

There are additional forms of conditional statements that use the keyword elif.

constructor call

A constructor call is a call to a constructor function. It has the form

    <classname>(<arguments>)

For example, Point(1,2,3) is a constructor call for the class Point.

A constructor call is evaluated in three steps:

  1. Create an instance of class classname
  2. Execute the initializer __init__(<arguments>)
  3. Return the folder name of the new instance
constructor

A constructor is a function that is used to make an instance of a class. It has the same name as the class. For example, the function Point() is the constructor for the class Point.


d

debugging

Debugging is the act of searching for and removing bugs in a program.

decorator

A decorator is a Python feature to provided extra functionality to a function or method definition. They typically begin with an @ symbol and appear on the line above the function header. Two popular uses of decorators in this class are class methods and properties. The creation of decorators is an advanced topic beyond the scope of this course.

default argument

A default argument is an argument that is provided automatically if it is omitted in the function call. Default arguments are specified by writing the associated parameter in the form of an assignment statement. For example, in the following function header has a default argument for y:

    def foo(x,y=2):

In this case, the function call foo(1) is legal; the y parameter is given the default argument 2.

delete statement

A delete statement is a statement used to eliminate a variable.
It does not just erase the contents of the box; it removes the entire box from memory.
A delete statement has the following form:

    del <variable>

Attempting to reference a variable after it is deleted will cause Python to raise an exception.

deprecate

A deprecated function or feature is used to be supported by a language, but is no longer guaranteed to work. Many Python features were deprecated in the move from Python 2 to Python 3, which is why Python 2 code sometimes does not work anymore.

dict

A dict or dictionary is a mutable type that associates keys with values. It is similar to a sequence, except that elements are accessed by the key, not the position. For example, in the dictionary

    d = { 'alpha':1, 'beta':3 }

the value d['alpha'] is 1, while the value d['beta'] is 3.

While dictionaries are not sequences, they are iterable.

docstring

A docstring is a string literal that begins and ends with three quotation marks. Document strings are used to write specifications and are displayed by the help() command.

duck typing

Duck typing is an alternate form of typing where the precondition only requires that an object has attributes or method with the right names. This much weaker than using the type() function because two completely different types could share the same attributes and methods.

The name is a reference to the phrase “If it looks like a duck and quacks like a duck, then it must be a duck.”


e

encapsulation

Encapsulation is the process of hiding parts of your data and implementation from users that do not need access it. This process makes it easier for you to make changes in your own code without adversely affecting others that depend upon your code. In Python, encapsulation is carried out by hiding the parts that the user cannot access.

Encapsulation is an important motivation for the concept of an interface.

escape character

The escape character \ is used to write characters that cannot appear directly in a string. Here are a few (not exhaustive) examples:

New-line Character \n
Backslash Character \\
Double-Quote Character \"
Single-Quote Character \'
evaluate

Python evaluates an expression by turning it into a value.

exception

An exception is a value that represents an error that has occurred in a program. When an exception is raised, Python stops the flow of execution and reports the exception to the user.

expression

An expression is Python code that, when executed, produces a value. The act of turning a Python expression into a value is evaluation. Many expressions look like something you might type into a calculator, such as 1+1 or True and False.

extend

One class extends another if it is a subclass of that class. For example, if SC is a subclass of class C, then SC extends C.


f

float

A float is a basic type whose values are scientific numbers like 3.46E-4.

folder

A folder is our running analogy for how information is stored in the heap. The following information is stored in folders:

The existence of folders is one of the reasons why we use the Python Tutor

folder name

The folder name is the unique identifier for a folder in the heap. This identifier can be accessed with the id() function, but it is rarely useful.

for-loop

A for-loop is a statement of the form

    for <variable> in <iterable>:
        <statements>

Python executes this statement as follows. It puts the first element of the iterable in the variable, and then executes the statements indented underneath. It repeats this process as long as there are still elements left in the iterable.

In a for-loop, the variable after the keyword for is called the loop-variable while the iterable is called the loop-iterable or loop-sequence.

fruitful function

A fruitful function is a function that terminates by executing a return statement and evaluates to the value returned. Fruitful functions (possibly) return a value other than None.

function

A function is a set of instructions to be carried out via a function call. You can think of it like a recipe in a cookbook. We often separate functions into fruitful functions and procedures.

function body

The function body consists of the lines of code specifying what is to be done when the function is called. The function body appears indented after the function header. We typically use the term function body to just refer to the actual Python code and exclude the function specification.

function call

An function call is an expression that executes a function body. It has the following form:

    <function-name>(<arguments>)

It is important to understand how a function call is executed. Its execution is performed in five steps:

  1. A call frame is added to the stack with the function name.
  2. The arguments are evaluated and assigned to the parameters.
  3. The function body is executed, one line at a time.
  4. The call frame is erased from the stack.
  5. The function value is returned if the function is fruitful.

If the function is a fruitful, it returns the value of the appropriate return statement. If it is a procedure, it returns None.

function definition

The function definition is the code that tells Python what to do when a function is called. It consists of the function header and function body.

function frame

A function frame is another term for a call frame.

function header

The function header is the part of the definition that starts with the keyword def, followed by the function name and the parameters delimited by parenthesis. The function body is immediately indented underneath.

function name

The function name is the name used to call a function. It appears in the function header, immediately after the keyword def.

function specification

The function specification defines what the function does. It is used to understand how to call the function. It must be clear, precise, and thorough, and it should mention all parameters, saying what they are used for. It should also include a precondition for each parameter.

In Python, function specifications are written with a docstring. They appear immediately after the function header, indented with the function body.

function stub

A function stub is a function definition with a header and specification, but not body.


g

generator

A generator is a special kind of function for creating an iterable. It is defined by placing a yield statement inside the function body. Calling a generator function returns an iterable object that uses this body to produce its elements.

getter

A getter is a method used to evaluate an object attribute. The purpose of the getter is to authorize a user to read the value of an attribute without allowing them to change it. Getters are often combined with hidden attributes to implement encapsulation. Many – but not all – getters are implemented as properties.

global space

Global space is the region of memory that stores global variables.

global variable

A global-variable is a variable that is defined outside of a function or class definition. Typically, both function names and module names are global variables; these variables each contain the identifier of the folder that stores the function or module content in the heap.


h

header, of a function

See function header.

header, of a method

See method header.

heap

The heap is the region of memory that stores all folders. Anything that is not a basic type must be represented as a folder in the heap.

hidden entity

A hidden entity is a Python attribute, variable, function, method, or class that will not be displayed when using the help() function. It is considered bad programming style and violation of encapsulation to use hidden entities that you yourself did not create.


i

immutable

The adjective immutable means “incapable of being changed”. It is typically used to refer to an attribute or a type.

immutable attribute

An immutable attribute is a hidden attribute that has a getter, but no setter. This implies that a user it not allowed to alter the value of this attribute. It is an important part of encapsulation.

immutable type

A immutable type is any type that is not mutable. All of the basic types are immutable.

implementation

An implementation is a collection of Python code for a function, module, or class) that satisfies a specification. This code may be changed at any time as long as it continues to satisfy the specification.

In the case of a function, the implementation is limited to the function body. In the case of a class, the implementation includes the bodies of all methods as well as any hidden attributes or methods. The implementation for a module is similar to that of a class.

import statement

An import statement is a statement with of the following forms:

    import <module>            # encapsulate contents in module folder 
    from <module> import item  # pull module element into global space

It is used to access the global variables, functions, and classes defined within a module. When we import a module, all module variables (and function and class names) are stored in a folder. Unless the from syntax is used, all content must be accessed using a variable with the same name as the module.

For example, if we use the statement

    import math

then we write math.pi to access the variable pi in this module. On the other hand, if we write

    from math import *

then all of the contents of the module math are dumped into global space. In that case we only need to write pi to access the same variable.

inherit

A subclass inherits all the class attributes and methods available in its superclass. This means that each instance of the subclass can access not only the attributes and methods defined in the class, but also those defined in the superclass.

In Python, instances of an subclass often also inherit the object attributes of instances of the super class. However, this is not guaranteed and it depends upon the specific definition of the initializer.

initializer

The initializer is the method used to populate the object attributes in a newly created (and empty) object. Its declaration has the following form:

    def __init__(self, <parameters>):

This method is executed by a constructor call after the creation of a new object. This method should not return anything as it is not the actual constructor.

initializer, default

The default initializer is what is used by the constructor if there is no explicit initializer in the class definition. If a class definition does not contain a initializer, it uses the one that inherits from its subclass, which may be the object class.

instance

An instance of a class is an object. The terms instance and object are synonyms. We typically use the word instance when we are referring to a collection of objects all of the same class.

instance method

An instance method is a method that is defined without the decorator @classmethod. All instance methods have self as their first parameter and must be called with an instance, not the class.

instantiate

The word instantiate means “to create an instance of”. Evaluation of a class expression C(...) instantiates an instance of the class C.

int

An int is a basic type whose values are integers.

interactive shell

The interactive shell is a program that allows the user to type Python expressions and statements one at a time, evaluating them or executing them them after each step. It is not to be confused with the command shell, which is a more general purpose tool. However, the interactive shell is often run within the command shell.

interface

The interface is the information that another user needs to know to use a Python feature, such as a function, module, or class. The simplest definition for this is any information displayed by the help() function.

For a function, the interface is typically the specification and the function header. For a class, the interface is typically class specification as well as the list of all unhidden methods and their specifications. The interface for a module is similar to that of a class.

is

The is operator works like == except that it compares folder names, not contents. The meaning of this operator is can never be overloaded.

iterable

An iterable type is the type of any value that may be used in a for-loop. Examples include lists, strings, and dictionaries


k

keyword

A keyword is a special reserved word telling Python to do something. Examples include if, for, and def. Keywords may not be used as variable names.


l

list

A list is a mutable type representing a sequence of values. Lists are represented as a comma-separated sequence of expressions inside square brackets, like this

    [1, 'Hello', True, 3.5]
literal

A literal is a way to represent a value in Python. Literals are used to write expressions with any of the basic types. Here are several examples of literals:

int 354
float 3.56
complex 3.5j
bool True
str "Hello World"
str 'Hello World'
local variable

A local variable is a variable that is created within the body of a function or method.

loop condition

The loop condition is a boolean expression in the header of a while-loop.

loop variable

A loop variable is a variable that acquires the next element of the loop iterable through each iteration of a for-loop.

In some cases, the term loop variable is extended to include any variable that appears in the loop condition of a while-loop.

loop iterable

A loop iterable is the entity that produces values for a for-loop. Because most loop iterables are sequences, this term is often used interchangeable with loop sequence.

loop sequence

A loop sequence is the entity that produces values for a for-loop. The name is chosen because most of the time for-loops use a sequences. However, the term loop iterable is more correct.


m

method

A method is a function that is contained within a class definition. Methods are able to access the attributes of the class, in addition to the parameters and local variables that any function can access.

method body

The method body is the function body of a method. When a method is called, its body is executed.

method call

A method call is a function call for a method. It is similar to a function call except that it has the following form: It has the following form:

    <folder>.<method-name>(<arguments>)

where <folder> is an object in the case of an instance method and a class in the case of a class method.

A method call creates a call frame exactly like a function call except that the folder name of <folder> is assigned to self.

method definition

The method definition is function definition for a method. It consists of the method header and method body.

method header

The method header is the function header for a method. All method headers are indented within the class definition. In addition, the first parameter of a method header should always be self.

method name

The method name is the name used to call a method. It appears in the method header, immediately after the keyword def.

method specification

A method specification defines what the method does. It is identical to a function specification except that it does not list an explicit precondition for the parameter self.

module

A module is a file containing global variables, function definitions, class definitions, and other Python code. The file containing the module must be the same name as the module and must end in .py. A module is used by either importing it or running it as a script.

module specification

A module specification is description of the purpose of a module and how to use it. Module specifications are typically written using docstrings.

mutable

The adjective mutable means “capable of being changed”. It is typically used to refer to an attribute or a type.

mutable attribute

An mutable attribute is an attribute that can be freely changed. Mutable attributes need not be encapsulated. But if the attribute is hidden, then it will need both a getter and a setter.

mutable type

A mutable type is a type where the values are containers, and it is possible to alter the contents of the container. An int is not mutable because it does not contain anything – it is just a number. A string is a container of characters but it cannot be changed. The types list and dictionary are examples of mutable types, as are most user-defined classes


n

narrower type

A narrower type is a type for which Python will perform a cast from automatically. In other words, Python will automatically cast from a narrower type to a wider type. This concept only applies to bool and the numeric types. The progression below shows the progression from narrowest type to the widest type:

    bool -> int -> float -> complex
None

The value None actually represents the absence of an value. If Python attempts an attribute reference like None.b or a method call like None.m(...), it will raise an exception.


o

object

An object is an instance of a class. Each object for a class can access the attributes and methods defined in and inherited by the class.

object attribute

An object attribute is an attribute that is unique to a specific object, and is therefore stored in the object folder.

object class

The object class is a special class built into Python named object. It is the superest class of all. Any class that does not extend another class must extend the object class.

object folder

The object folder is the folder in the heap that contains the attribute values unique to an object. We use this term to in place of the term object when we want to exclude any attributes or methods that might be inherited.

object identifier

The object identifier is the folder name for an object-folder. This identifier can be accessed with the id() function, but it is rarely useful.

object representation

A object representation is a string that can uniquely identify an object. It is retrieved with the repr function.

operator overloading

Operator overloading is the ability to redefine the behavior of various operator symbols (+, *, /, etc.) in Python. The name refers to the fact that an operator can have many different “meanings” and the correct meaning depends on the type of the objects involved.

In operator overloading, Python looks at the type of the object on the left. If it is a built-in type, it uses the meaning for that type. Otherwise, it looks for the associated special method (beginning and ending with double underscores) in the class definition.

operator precedence

Standard mathematics gives precedence to multiplication * over addition +, so that the expression 2 + 3 * 5 is evaluated as if it were parenthesized as 2 + (3 * 5). The precedence used in Python for all operators is given on this page.

override

A method that is inherited from a class can be overridden by redeclaring it in the subclass. The buttom-up rule ensures that the overriding method will be called, rather than the inherited one.


p

parameter

A parameter is a variable that is declared within the header of a function or method.

pass statement

A pass statement is a statement that tells Python to do nothing. It is used to fill the body of a function stub.

postcondition

A postcondition is an assertion that indicates what is to be true at the end of a sequence of statements, often a function body or while-loop.

precedence of operators

See operator precedence.

precondition

A precondition is an assertion that indicates what must be true at the beginning of a function body or – more generally - any sequence of statements. Preconditions are critical for assigning responsibility in code development.

procedure

A procedure is a function that has no explicit return statement. A function call on a procedure always evaluates to None.

property

A property is a special type of attribute which acts like a variable, but is not actually a variable. Attempts to use a property are substituted with method calls, according to its setter and getter methods. Properties are creating by attaching the decorator @property to the getter.

The purpose of properties is to enforce the class invariant.


r

raise exception

When Python *raises an exception**, it stops the execution as the result of an error. The details of the error are stored in an exception.

representation, object

See object representation.

return statement

A return statement is a statement which terminates the execution of the function body in which it occurs. If it is followed by an expression, then the function call returns the value of that expression. Otherwise, the function call returns None.


s

scope

The scope of a variable is the set of statements in which it can be referenced. For a parameter, it is the corresponding function body. For a local variable, it is from the initial assignment statement until the variable is deleted, or the end of the function body.

script

A script is a python program that is meant to be run outside of interactive mode. In particular, scripts often have the following line of code to prevent them from being imported:

    if __name__ == "__main__":

To run an script, type python <script> in the the OS command shell. When a script is run, it will execute all of the code indented under the conditional above.

self

The keyword self is used to reference the object associated with the current method call. Every method header must have self as its first parameter.

sequence

A sequence is a value that is an ordered list of other values. The contents of a sequence can be accessed by bracket notation. For a sequence seq, seq[2] is the element in position 2. seq[1:5] is the slice (subsequence) from positions 1 to 5 (including 1, but not including 5).

Examples of sequences include lists, strings, and tuples.

setter

A setter is a method used to assign a value to an object attribute. A setter is ise to restrict the values that can be assigned to the attribute, enforcing the class invariant. Many – but not all – setters are implemented as properties using the decorator @setter.

specification, class

See class specification.

specification, function

See function specification.

specification, module

See module specification.

statement

A statement is a command of Python to do something. Python executes a statement.

str

A str or string is a basic type whose values are text, or sequences of characters. String literals must be either in double or single quotes.

subclass

A class SC is a subclass of class C if the definition of SC contains C in parentheses after the class name. This means that every instance of class SC inherits all the components of class C.

super

The function super() is used to call an inherited method in a class, rather than the overriding one.

superclass

A class C is a superclass of class SC if SC is a subclass of C.


t

test-case

A test-case is a collection of inputs, together with an expected output, used to test a single run of a program. It is often used in unit tests to test a function.

testing

Testing is the act of analyzing a program, looking for bugs. Unlike debugging, it does not necessarily involve removing bugs.

try-except statement

A try-except statement is a statement of the following form

try:
    <statements>
except:
    <statements>

Python attemtps to execute all of the statements underneath try. If there is no error, then Python does nothing and skips over all the statements underneath except. However, if Python crashes while inside the try portion, it recovers and jumps over to the except. It then executes all the statements underneath there.

try-except statement, limited

A limited try-except statement is a try-except statement that only recovers for certain types of errors. It has the form

try:
    <statements>
except <class>:
    <statements>

where the class is the name of an exception type. Unlike a normal try-except statement, this version only jumps to the except if the raised exception is an instance of the error class.

tuple

A tuple is a immutable type representing a sequence of values. Tuples are represented as a comma-separated sequence of expressions inside parentheses, like this

    (1, 'Hello', True, 3.5)
type

A type is a set of values together with the operations on them. The type of a value can be determined via the type() function.

typing

Typing is a special form of precondition that requires that a variable hold a value of a specific type. It is the most common form of function precondition in this course.


u

unit test

A unit test is a collection of test cases used to test a unit of code, typically a function or method.


v

variable

A variable is name with an associated value. We sometimes refer to it as a named box with the value in the box. In Python, there are four basic kinds of variable, determined by the memory region they fit in:


w

while-loop

A while-loop is a statement with the following form:

while <bool>:
	<statements>

Python executes this statement as follows. It first evaluates the boolean expression. If it is True, then it executes the statements indented underneath. It repeats this process as long as the boolean expression is true. This boolean expression is often referred to as the loop condition.

While-loops are difficult to use properly and are often combined with loop invariants.

wider type

A wider type is a type for which Python will perform a cast from automatically. In other words, Python will automatically cast from a narrower type to a wider type. This concept only applies to bool and the numeric types. The progression below shows the progression from narrowest type to the widest type:

    bool -> int -> float -> complex

y

yield statement

A yield statement is a statement which temporarily pauses the execution of a generator or coroutine. It produces the next value in the iterable associated with the generator or coroutine.


Acknowledgments

This document was originally written by David Gries to accompany the Java version of CS 1110. It has since been adapted to Python 3, and the modern conventions of CS 1110, by Walker White.