Monday: 3.1 and 3.2 Variables, Assignments, and Data Abstractions

  • A variable is an abstraction inside a program that can hold a value, and can organize data by labeling it with a descriptive nam

  • It has 3 elements, name, value, and type

Naming Variables

  • Do’s: Keep it simple, easy to read. Diffferentiate the words with a capital letter, to make it easy to read. make sure they have enough specifics and not vague. Spaces are not a proper syntax. dashes and numbers are also improper syntax and should be avoided

Types of Data

  • Integers (Numbers) Text/string (A word) Boolean (Data that determines if something is true or false)

  • Lists of data can be stored in variables, and it is useful to print/retrieve specific values without creating a lot of variables, and wasily removing/adding/changing items into the list.

Assignments

  • The assignment operator allows program to change the value represented by a variable

  • Used to assign Values

  • The Value stored in a variable will always be the most recent value assigned

  • num1 = 5
  • num2 = 9
  • num1 = num2

  • 9 twice

Data Abstraction

  • Data Abstraction is a methof used to represent data in a useful form, by taking away aspects of data that aren’t being used in this situation

Lists and Strings

  • Lists = Ordered sequence of elements

  • Element = individual value in a list that is assigned to a unique index

  • Index = a way to reference the elements

  • 1: Green
  • 2: Blue
  • 3: Purple

  • What is the purpose: They help manage complexity by giving a collection of data a name without referencing specific details

  • Lists allow for data abstraction, bundle variables together, store multiple elements, allows multiple related elements

    1. Assigning values to a list at certain indices
    1. Creating an empty list and assigning it to a variable
    1. Assigning a copy of a list to another one
  • Index starts at 1, not 0

  • Homework: Make a program that utilizes lists as the primary function (quiz)