π

All Subjects

Β >Β

β¨οΈΒ

AP Comp Sci P

Β >Β

π±

Big Idea 3: Algorithms and Programming

# Data Abstraction

Minna Chow

### AP Computer Science PrinciplesΒ β¨οΈ

BookmarkedΒ 2.9kΒ β’Β 79Β resources
See Units

## Lists in APCSP Pseudocode

Here's what a list looks like in AP Pseudocode.
An element is an individual value in a list: in the example above, value1, value2, and value3 are all elements. Each element is assigned an index value, or a number representing their place in the list.
In the AP CSP Pseudocode, index numbers start at 1, so in the example above value1 would have an index of 1, value2 an index of 2, and so on. Index values are commonly used to reference and to work with the elements in a list.
This is a key difference from Python, where the index values start at 0.
You saw in the last example how you can assign a filled-in list to a variable.
You can also assign an empty list to a variable...
and one list to another.
Lists can be used to create data abstraction. Data abstraction simplifies a set of data by representing it in some general way. You can then work with that representation instead of each piece of data itself.
For a very basic example, let's say you want to make a program that will print your to-do list out. You could manually insert values into your program to print, like so:
`print ("My To-Do List is:" " Write essay", "Read Chapter 2", "Finish Math HW", "Attend Fiveable Class")`
```to_do = ["Write essay", "Read Chapter 2", "Finish Math HW", "Attend Fiveable Class"] print ("My To Do List is:") print (to_do)```
Now, instead of working with the data itself (the things on your to-do list), you're working with a variable, to_do, that represents the data.
There are several advantages to this. For one, it makes your code neater and easier to read. It also allows you to edit the data easily. If you wanted to print a different list in the first example, you would have to erase your code entirely and rewrite it.
By using a variable to represent the list, all you have to do is create a new list under a different name and use that variable instead.
```new_to_do = ["Read Gatsby", "Practice Driving", "Go for walk"] print ("My To Do List is:") print (new_to_do)```
Using a list also allows you to work easily with individual elements within it, as you'll see below.
By using data abstraction, you can create programs that are easier to build and maintain.

Studying with Hours = the ultimate focus mode
Start a free study session
Browse Study Guides By Unit
πΉBig Idea 1: Creative Development
βοΈBig Idea 2: Data
π±Big Idea 3: Algorithms and Programming
π₯Big Idea 4: Computer Systems and Networks
β¨οΈBig Idea 5: Impact of Computing