Key Points

  • Variables are abstractions within programs which represent a value
  • Values can be individual data points or a list/collection that contains many data values
  • Types of data: numbers, Booleans (T/F), lists, and strings
  • Python
  • JavaScript

Variables

  • Represent a value with a variable
    • Strings
    • lists
    • booleans
    • numbers
  • Determine the value of a variable as a result of an assignment

Example for variables

x = 5
y = "Ananya"
print(x)
print(y)
5
Ananya

Mathematical Experessions

  • Addition is +
  • Subtraction is -
  • Multiplication is *
  • Division is /
  • Modulus is %
  • Exponentiation is **
  • Floor division is //

Example for Mathematical Experessions

x = 5
y = 6
z = 5 + 6
print(z)
11

Data Types

  • Numeric Types: int, float, complex
  • Sequence Types: list, tuple, range
  • Mapping Type: dict
  • Set Types: set, frozenset
  • Boolean Type: bool
  • Binary Types: bytes, bytearray, memoryview

Example for Datatypes

number = 20.3   
x = number/10   
y = number*2   
print(number)   
print(x)   
print(y)   
print(x*y)   
20.3
2.0300000000000002
40.6
82.418

3.2 Notes

Key Points

  • A list is made up of elements organized in a specific order
    • An element is a unique, individual value in a list
    • A string differs from a list as it is a sequence of characters rather than elements
    • Data abstraction uses a list by taking specific data elements from a list and organizing into a whole, less complex - - representation of the values such as a table
    • Python
    • JavaScript

What is data abstraction?

  • Data abstraction provides a separation between the abstract properties of a data type and the concrete details of its representation
    • data abstractions manage complexity in programs by giving a collection of data a name without refrencing the specific elements of the representation
    • Data Abstraction makes it easier to implement, develop and maintain code

Lists

What are lists

  • Lists are used to store multiple items in a single variable.
  • Lists are one of 4 built-in data types in Python used to store collections of data, the other 3 are Tuple, Set, and - Dictionary, all with different qualities and usage.

Example for lists

thislist = ["dog", "cat", "cows", "pig"]
print(thislist)
['dog', 'cat', 'cows', 'pig']

List Items

  • List items are ordered, changeable, and allow duplicate values.
  • List items are indexed, the first item has index [0], the second item has index [1] etc
thislist = ["apple", "banana", "cherry"]
print(thislist[1:2])
['banana']