Variables, Assignments, and Abstractions
Notes on Variables, Assignments, and Abstractions
Variables, Assignments, and Data Abstractions
An abstraction inside a program that can hold a value
Naming Variables
Tip: Make variables simple, easy to read, and relatively general for efficient code Ex: Do: highscore Don’t: highestscoreinthegame
Types of Data
- Integer: numbers
- Text: words
- Boolean: states if something is true or false
Assignments
allows a program to be change the value represented by a variable assigns values to varibales
Examples
Example 1 a=1 a=b a=2 print(b) b=1
- will take the most recent value
Example 2 num1 = 5 num2 = 9 num1 = num2 print(num1) 9 print(num2) 9
Data Abstraction
represent data in a useful form; manages complexity
- List and Indexes start at 1
- Maximum number is the # of elements in the list
- string = ordered sequencce of characters
3 Types of List operations
- Assigning values to a list of certain indicies
- Creating an empty list and assigning it values
- Assigning a copy of a list