#!/usr/bin/env python # coding: utf-8 # # Terms cheat sheet # In general, it will be in the form: # # **term**: definition # - Example ways to use it in a sentence # ```python # 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)" # ```python # 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" # In[ ]: # **Variable**: a way to store a value # - "Store 10 in the variable x", "store 10 in x" # ```python # x = 10``` # - "Store the value of z in the variable x", " # ```python # 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" # ```python # x = 10``` # **Operator, operation**: special symbols that carry out arithmetic or logical computation # - "Use the plus operator to add 1 and 3" # ```python # 1 + 3``` # # **Logical operator**: specifically for operators regarding boolean values # - "Use the `and` operator" # ```python # True and False``` # In[ ]: # **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" # ```python # x[5]``` # - "retrieve the 0th element of a list" # ```python # x[0] # ``` # # **Negative indexing**: retrieving a single element using negative numbers # - "index -1" # ```python # 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?) # ```python # x[0:4]``` # - "get the slice of x from 0 to 3, inclusive" # ```python # x[0:4]``` # In[ ]: # **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..." # In[ ]: # **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" # In[ ]: