Study smarter with Fiveable
Get study guides, practice questions, and cheatsheets for all your subjects. Join 500,000+ students with a 96% pass rate.
Every piece of data your program handles—from a user's age to their entire shopping cart—needs to be stored in a specific format that tells the computer how to work with it. Data types are the foundation of how programming languages organize, store, and manipulate information. When you're tested on this material, you're not just being asked to define what an integer is—you're being evaluated on whether you understand why you'd choose one data type over another, how different types behave in operations, and what happens when types interact or convert.
Think of data types as falling into categories based on their purpose: primitive types that hold single values, collection types that group multiple values together, and special types that handle unique situations like missing data or complex objects. Don't just memorize definitions—know what problem each data type solves and when you'd reach for one over another. That conceptual understanding is what separates students who ace exams from those who struggle with application questions.
These are your workhorses for mathematical operations. Numeric primitives store individual numbers directly in memory, making them fast and efficient for calculations.
if x == 0.1)Compare: Integer vs. Float—both store numbers, but integers are exact while floats can represent fractions at the cost of potential precision errors. If an exam asks when to use each, remember: counting = integer, measuring = float.
These types handle human-readable data. Characters are the atomic unit; strings are sequences of characters that form meaningful text.
'A', '7', '@')'A' < 'B' evaluates to true)substring(), toUpperCase(), split(), trim()—know these for practical coding questionsCompare: Character vs. String—a character holds exactly one symbol while a string holds zero or more. Some languages (like Python) don't have a separate character type; a single character is just a string of length 1.
These types handle truth values and edge cases that don't fit neatly into numeric or text categories.
true or false, named after mathematician George Booleif, while) and is the result of all comparison operations ( returns true)AND, OR, NOT) combine booleans for complex conditions—truth tables are commonly testedCompare: Boolean false vs. Null—both are "falsy" in many languages, but they mean different things. False is a definite answer ("no"), while null means "no answer exists." Confusing these is a common source of bugs.
When you need to store multiple values, collection types organize them efficiently. The key differences are whether elements are ordered, whether they can change size, and how you access them.
Compare: Array vs. List—arrays are faster and more memory-efficient but inflexible; lists sacrifice some performance for convenience. Choose arrays for performance-critical code with fixed data, lists for flexibility.
{"name": "Alice", "age": 25})Compare: List vs. Dictionary—lists access elements by numeric index (position), dictionaries access by meaningful keys. Use lists for ordered sequences, dictionaries when you need to look up values by name or identifier.
Objects bundle data and behavior together, enabling more complex and reusable code structures.
Compare: Primitive types vs. Objects—primitives hold single values directly, while objects can hold multiple values plus the functions to manipulate them. Objects are passed by reference (changes affect the original), while primitives are typically passed by value (changes create copies).
| Concept | Best Examples |
|---|---|
| Numeric computation | Integer, Float |
| Text handling | String, Character |
| Decision logic | Boolean |
| Handling missing data | Null/None |
| Fixed collections | Array |
| Dynamic collections | List |
| Key-based lookup | Dictionary/Map |
| Complex data modeling | Object |
You need to store a student's GPA (like 3.75). Would you use an integer or a float, and why might using the wrong type cause problems?
Compare and contrast arrays and lists: what are two situations where you'd prefer an array, and two where a list would be better?
A program crashes with a "null reference" error. Explain what null represents and how you would prevent this type of error.
If you're building a phone contact list where you look up numbers by name, which data type would you choose and why? What would be the keys and values?
Why is it dangerous to compare two float values using == for exact equality? What concept about floating-point storage explains this behavior?