---
title: "Variable — AP CSP Definition, Assignment & Exam Guide"
description: "A variable is a named abstraction that holds one value at a time in a program. Master assignment with ←, lists, and traversal for the AP CSP exam."
canonical: "https://fiveable.me/ap-comp-sci-p/key-terms/variable"
type: "key-term"
subject: "AP Computer Science Principles"
unit: "Unit 3"
---

# Variable — AP CSP Definition, Assignment & Exam Guide

## Definition

In AP Computer Science Principles, a variable is an abstraction inside a program that holds one value at a time, though that value can be a list containing many elements (EK AAP-1.A.1). You change a variable's value with the assignment operator ←, and the variable keeps the most recent value assigned.

## What It Is

A variable is a named box your [program](/ap-comp-sci-p/unit-1/program-function-purpose/study-guide/8hL8KatG4rAWTwZSglGB "fv-autolink") uses to hold a value. The CED is precise about this. Each variable represents exactly one value at a time, but that one value can be a [list](/ap-comp-sci-p/unit-3/data-abstraction/study-guide/kMMTClSiHohfiaHMGFFE "fv-autolink") or another collection that itself holds multiple values (EK AAP-1.A.1). So `scores` is one variable even if it stores fifty test scores.

On the AP exam, you work with variables using the assignment operator from the reference sheet, written as `←`. The statement `a ← expression` evaluates the [expression](/ap-comp-sci-p/key-terms/expression "fv-autolink") first, then assigns a copy of the result to `a` (EK AAP-1.B.2). The single most-tested rule is that a variable holds the most recent value assigned to it. In `a ← 1`, `b ← a`, `a ← 2`, the variable `b` still holds 1, because `b` got a copy of `a`'s value at that moment, not a permanent link to `a`. Variables can reference different data types, including numbers, Booleans, strings, and lists (EK AAP-1.A.3), and using meaningful names like `studentCount` instead of `x` makes code readable (EK AAP-1.A.2).

## Why It Matters

Variables live in Topic 3.1 (Variables and Assignments) in [Unit 3](/ap-comp-sci-p/unit-3 "fv-autolink"): [Algorithms](/ap-comp-sci-p/key-terms/algorithm "fv-autolink") and Programming, supporting learning objectives 3.1.A (represent a value with a variable) and 3.1.B (determine the value of a variable after an assignment). But they don't stay there. Topic 3.2 (LO 3.2.A) has you represent lists and strings with variables, and Topic 3.10 has you assign list elements to variables with `x ← aList[i]` and use the loop variable in `FOR EACH item IN aList`. Practically everything else in Unit 3, including conditionals, procedures, and simulations, is built on reading and updating variables. If you can trace what a variable holds line by line, you can answer a huge slice of the Unit 3 multiple-choice questions.

## Connections

### Data Abstraction (Unit 3)

A variable holding a list is the AP CSP version of data abstraction. You give a whole [collection](/ap-comp-sci-p/unit-3/variables-assignments/study-guide/vtJhAf5XFOkm1uHNDMvh "fv-autolink") of data one name, like `playlist`, and stop worrying about the individual values inside it (EK AAP-1.D.2). That's how abstraction manages complexity.

### [List Traversal (Unit 3)](/ap-comp-sci-p/key-terms/list-traversal)

In `FOR EACH item IN aList`, the variable `item` is automatically assigned each element of the list in order, first to last. A traversal is really just a variable getting reassigned over and over, which is why LO 3.1.B skills show up inside loop questions.

### [Data Type (Unit 3)](/ap-comp-sci-p/key-terms/data-type)

Variables reference values that have types, and EK AAP-1.A.3 names the ones you need to know for the exam. They are numbers, Booleans, [lists](/ap-comp-sci-p/unit-3/lists/study-guide/mCE6meIGp5pqs1y5ym3h "fv-autolink"), and strings. The type determines what operations make sense, like indexing into a string versus dividing a number.

### Constant (Unit 3)

A constant is the variable's stubborn cousin. Both are named values, but a variable's value is meant to change through reassignment while a constant stays fixed for the whole program. [AP pseudocode](/ap-comp-sci-p/key-terms/ap-pseudocode "fv-autolink") questions almost always test the changing kind.

## On the AP Exam

Multiple-choice questions test you on tracing. You'll see a code segment with several `←` assignments and be asked for a variable's final value, and the trap is always forgetting that assignment copies a value rather than linking two variables. List versions of this ask you to evaluate `aList[i]` or determine what a swap does, like assigning `temp ← dataValues[1]` before overwriting it (a classic three-step swap question). On the Create performance task's written response, variables are front and center. The 2026 Written Response Q2 asks you to identify the variable in the first iteration statement of your Personalized Project Reference, and the 2023 scoring criteria rewarded correctly describing what your program's variables and lists represent. Remember the AP pseudocode quirk that list indexing starts at 1, not 0.

## Variable vs Constant

Both are named storage for a value, but a variable's value can change during program execution through assignment, while a constant is set once and never reassigned. AP CSP pseudocode questions focus on variables because the whole point of LO 3.1.B is determining a variable's value after a series of assignments. If a value never changes, there's nothing to trace.

## Key Takeaways

- A variable holds exactly one value at a time, but that value can be a list that contains many elements (EK AAP-1.A.1).
- The assignment operator ← evaluates the expression on the right first, then assigns a copy of the result to the variable on the left.
- A variable always stores the most recent value assigned to it, so in `a ← 1`, `b ← a`, `a ← 2`, the variable b is still 1.
- AP pseudocode lists are indexed starting at 1, so `aList[1]` is the first element, and `x ← aList[i]` copies an element's value into a variable.
- In `FOR EACH item IN aList`, the variable `item` takes on each element's value in order from first to last.
- Meaningful variable names like `totalScore` make code readable and make it clear what value the variable represents (EK AAP-1.A.2).

## FAQs

### What is a variable in AP Computer Science Principles?

A variable is an abstraction inside a program that holds one value at a time, with that value changeable through the assignment operator ← (EK AAP-1.A.1). The value can be a number, Boolean, string, or even an entire list.

### If I write b ← a and then change a, does b change too?

No. Assignment copies the value at that moment, so b keeps whatever a held when the assignment ran. The CED's own example is `a ← 1`, `b ← a`, `a ← 2`, where displaying b still shows 1 (EK AAP-1.B.3).

### How is a variable different from a constant in AP CSP?

A variable's value can change during program execution through reassignment, while a constant is assigned once and stays fixed. Exam tracing questions are built around variables changing, since LO 3.1.B asks you to determine a variable's value after a series of assignments.

### Can a variable hold more than one value in AP CSP?

Sort of. A variable holds exactly one value at a time, but that single value can be a list containing multiple elements (EK AAP-1.A.1). So `grades ← [90, 85, 77]` is one variable holding one list with three elements.

### Does AP CSP pseudocode start list indexing at 0 or 1?

At 1, unlike Python or Java. The first element of aList is aList[1], so when you trace a variable assignment like `x ← aList[2]`, x gets the second element. Forgetting this is one of the most common MCQ mistakes.

## Related Study Guides

- [3.2 Data Abstraction](/ap-comp-sci-p/unit-3/data-abstraction/study-guide/kMMTClSiHohfiaHMGFFE)
- [3.10 Lists](/ap-comp-sci-p/unit-3/lists/study-guide/mCE6meIGp5pqs1y5ym3h)
- [3.1 Variables and Assignments](/ap-comp-sci-p/unit-3/variables-assignments/study-guide/vtJhAf5XFOkm1uHNDMvh)

## Structured Data

```json
{"@context":"https://schema.org","@graph":[{"@type":"LearningResource","@id":"https://fiveable.me/ap-comp-sci-p/key-terms/variable#resource","name":"Variable — AP CSP Definition, Assignment & Exam Guide","url":"https://fiveable.me/ap-comp-sci-p/key-terms/variable","learningResourceType":"Concept explainer","educationalLevel":"AP® / High School","about":{"@id":"https://fiveable.me/ap-comp-sci-p/key-terms/variable#term"},"audience":{"@type":"EducationalAudience","educationalRole":"student"},"dateModified":"2026-06-12T22:52:53.847Z","isPartOf":{"@type":"Collection","name":"AP Computer Science Principles Key Terms","url":"https://fiveable.me/ap-comp-sci-p/key-terms"},"publisher":{"@type":"Organization","name":"Fiveable","url":"https://fiveable.me"}},{"@type":"DefinedTerm","@id":"https://fiveable.me/ap-comp-sci-p/key-terms/variable#term","name":"Variable","description":"In AP Computer Science Principles, a variable is an abstraction inside a program that holds one value at a time, though that value can be a list containing many elements (EK AAP-1.A.1). You change a variable's value with the assignment operator ←, and the variable keeps the most recent value assigned.","url":"https://fiveable.me/ap-comp-sci-p/key-terms/variable","inDefinedTermSet":{"@type":"DefinedTermSet","name":"AP Computer Science Principles Key Terms","url":"https://fiveable.me/ap-comp-sci-p/key-terms"}},{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"What is a variable in AP Computer Science Principles?","acceptedAnswer":{"@type":"Answer","text":"A variable is an abstraction inside a program that holds one value at a time, with that value changeable through the assignment operator ← (EK AAP-1.A.1). The value can be a number, Boolean, string, or even an entire list."}},{"@type":"Question","name":"If I write b ← a and then change a, does b change too?","acceptedAnswer":{"@type":"Answer","text":"No. Assignment copies the value at that moment, so b keeps whatever a held when the assignment ran. The CED's own example is `a ← 1`, `b ← a`, `a ← 2`, where displaying b still shows 1 (EK AAP-1.B.3)."}},{"@type":"Question","name":"How is a variable different from a constant in AP CSP?","acceptedAnswer":{"@type":"Answer","text":"A variable's value can change during program execution through reassignment, while a constant is assigned once and stays fixed. Exam tracing questions are built around variables changing, since LO 3.1.B asks you to determine a variable's value after a series of assignments."}},{"@type":"Question","name":"Can a variable hold more than one value in AP CSP?","acceptedAnswer":{"@type":"Answer","text":"Sort of. A variable holds exactly one value at a time, but that single value can be a list containing multiple elements (EK AAP-1.A.1). So `grades ← [90, 85, 77]` is one variable holding one list with three elements."}},{"@type":"Question","name":"Does AP CSP pseudocode start list indexing at 0 or 1?","acceptedAnswer":{"@type":"Answer","text":"At 1, unlike Python or Java. The first element of aList is aList[1], so when you trace a variable assignment like `x ← aList[2]`, x gets the second element. Forgetting this is one of the most common MCQ mistakes."}}]},{"@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"AP Computer Science Principles","item":"https://fiveable.me/ap-comp-sci-p"},{"@type":"ListItem","position":2,"name":"Key Terms","item":"https://fiveable.me/ap-comp-sci-p/key-terms"},{"@type":"ListItem","position":3,"name":"Unit 3","item":"https://fiveable.me/ap-comp-sci-p/unit-3"},{"@type":"ListItem","position":4,"name":"Variable"}]}]}
```
