AP Computer Science Principles Flashcards: Variables and Assignments
Written by AP Content Team, Verified for 2026 AP Exams, Last updated: May 2026
Review key ideas with interactive flashcards. This set includes 19 cards to help you master important concepts.
List four common data types that variables can represent.
Common data types include numbers, Booleans, lists, and strings.
Card 1 of 19
All Flashcards (19)
List four common data types that variables can represent.
Common data types include numbers, Booleans, lists, and strings.
Why are meaningful variable names important?
Using meaningful variable names helps with the readability of program code and understanding of what values are represented by the variables.
How is the current value of a variable determined if it has been assigned multiple times?
The value stored in a variable will always be the most recent value assigned to it.
Can a single variable hold more than one individual value?
Yes, a variable's value can be a list or other collection that in turn contains multiple values.
What is the assignment operator?
The assignment operator allows a program to change the value represented by a variable by assigning the result of an expression to it.
Which variable name is more readable for storing a player's high score: `s` or `highScore`?
The variable name `highScore` is more readable because it clearly describes the value it represents.
A program needs to store a list of student names. What data type should be used for the variable?
A list should be used, as it is a collection that can contain multiple values, such as a series of strings representing names.
What symbol for assignment is provided on the AP exam reference sheet?
The exam reference sheet provides the " ← " operator to use for assignment.
Which data type is best suited to represent if a statement is true or false?
The Boolean data type is best suited for representing true or false values.
What is the primary purpose of using a variable in a program?
The primary purpose of a variable is to represent a value, allowing that value to be stored, accessed, and modified within the program.
Describe the process of an assignment operation.
The assignment operator first evaluates an expression and then assigns a copy of the result to the variable.
What data type would be best to represent a person's age in whole years?
A number type would be the best data type to represent a person's age.
What is the final value of `x` after this code runs?
`x ← 5`
`x ← 12`
The final value of `x` is 12, as it was the most recent value assigned.
A program executes the line `score ← 100`. What is the value of the variable `score`?
The value of the variable `score` is 100.
Determine the value of `b` after this code runs:
`a ← 42`
`b ← a`
The value of `b` is 42. The expression on the right (`a`) is evaluated to 42, and a copy of this result is assigned to `b`.
What is a variable?
A variable is an abstraction inside a program that can hold a value. Each variable has associated data storage that represents one value at a time.
In what sense is a variable an 'abstraction'?
A variable is an abstraction because it provides a simple name to represent a potentially complex piece of data stored in computer memory, hiding the details of the storage itself.
How do variables relate to data types in some programming languages?
Some programming languages provide types to represent data, and variables are used to reference values of these specific types.
Why is it important to choose a suitable data type for a value?
Some values are better suited to representation using one type of datum rather than another, which affects how they can be stored and manipulated.