Terms cheat sheet

In general, it will be in the form:

term: definition

  • Example ways to use it in a sentence
    code
    

Syntax: the rules of a langauge

  • "The syntax for for loops"
  • "The syntax for if statements"
  • "The syntax of defining a function"

Syntax error: the misuse of a language that results in an error

  • "The following code has a syntax error (it is missing in)"
    for i range(5):
      print(i)
    

Comment: a piece of code that does not run. In Python, comments begin with the # symbol

  • "Write a comment that describes the function"
  • "Comment out that piece of code"

Variable: a way to store a value

  • "Store 10 in the variable x", "store 10 in x"
    x = 10
    
  • "Store the value of z in the variable x", "
    z = x
    

Type: the kind or category of a value. Every value has a type.

  • "The type of 5 is an int"
  • "The type of 5.0 is a float"

Assignment, assigning: the act of putting a value in a variable

  • "Assign 10 to x"
    x = 10
    

Operator, operation: special symbols that carry out arithmetic or logical computation

  • "Use the plus operator to add 1 and 3"
    1 + 3
    

Logical operator: specifically for operators regarding boolean values

  • "Use the and operator"
    True and False
    

List/array: a type of value that contains an (ordered) sequence of other values

  • "Make a list that contains 1 and 5.0
  • "Make an array of strings"

List index: the location of an element in a list

Indexing: the action of retrieving a single element from a list

  • "index 5 of a list"
    x[5]
    
  • "retrieve the 0th element of a list"
    x[0]
    

Negative indexing: retrieving a single element using negative numbers

  • "index -1"
    x[-1]
    

List slice: a portion of a list (also a list)

Slicing: the action of retrieving a portion of a list

  • "slice x from 0 to 3, inclusive" (why is it up to 4?)
    x[0:4]
    
  • "get the slice of x from 0 to 3, inclusive"
    x[0:4]
    

Function: a piece of code that is used for repeating work. Functions are "called" or "invoked". A function takes 0 or more arguments and is only run when called. Functions "return" a value.

  • "A function that returns the average of a list"
  • "A function that returns the sum of a list"
  • "A function that turns a string to lower case"

Argument/parameters: a value that is passed to a function when the function is called. Arguments are "passed" to functions and a function "takes" an argument

  • "Pass x to the function"
  • "Write a function that takes an argument x that..."

Conditional/Control flow: a way of changing the program behavior depending on a condition

If statement: A way of adding control flow to a program

Loop: A piece of code that runs itself repeatedly. Commonly used to run a piece of code over every value in a list. In this course, we will use for and while loops.

  • "Loop over the list L"
  • "Use a loop to sum the numbers from 0 to n-1"