Data types, lists, and objects
Think about a single order in a coffee app.
The order might contain a customer’s name, the total price, whether the order has been paid, and a list of drinks.
These are all pieces of data, but they are not the same kind of data. A customer’s name is text, a price is a number, payment status is a yes-or-no value, and the drinks are a collection of several values.
Programming languages make these differences explicit through data types.
What is a data type?
A data typeConcept · lights on your mapdata typeThe kind of value a program is working with. It determines what the value represents and what can be done with it. The ones you meet constantly are strings, integers, and booleans. describes the kind of value a program is working with.
The type helps the programming language understand what the value represents and what operations can be performed on it.
Numbers can be added together, for example, text can be displayed or combined into longer text, and a true-or-false value can help a program make a decision.
Programming languages contain many data types, but a few appear constantly in simple code.
Strings: text
A string is a sequence of text characters.
Strings are normally surrounded by quotation marks: customer_name = "Erik"
The quotation marks tell Python that "Erik" should be treated as text rather than as the name of a variable or instruction.
Strings can contain letters, spaces, punctuation, and digits:
drink_name = "vanilla latte"order_message = "Your order is ready!"zip_code = "22201"
Although a ZIP code contains digits, it is commonly stored as text because it is used as an identifier rather than for arithmetic.
Numbers: integers and floats
Programs commonly work with more than one kind of number.
An integer is a whole number without a decimal point: drink_count = 3
A float, short for floating-point number, is a number that can contain a decimal point: order_total = 14.50
You do not need to understand how floating-point numbers are stored internally. For now, remember:
3is an integer.14.50is a float.- Both are number types.
Some programming languages classify numbers differently, but this distinction is common.
Booleans: true or false
A boolean is a value that can have only one of two states: True or False
The word comes from George Boole, a mathematician who studied systems of true-and-false logic.
A coffee application might use a boolean to remember whether an order has been paid: paid = False
After the payment succeeds, the program could change the value: paid = True
In Python, True and False begin with capital letters. Other languages may write them differently. The underlying idea is the same.
Why quotation marks matter
Compare these two values: 3 and "3"
The first is the number three, while the second is a string containing the character 3.
They may look similar to a person, but the computer treats them differently.
Numbers can be used in arithmetic: 3 + 2 produces 5
Strings are pieces of text. In many programming languages, combining strings joins them together: "3" + "2" may produce 32
The computer is not making a mistake. It was instructed to combine two pieces of text rather than add two numbers.
Confusing numbers and strings is a common source of software problems because the value’s type determines how the program interprets it.
Lists: several values in order
Real products often need to keep track of several related values.
A coffee order, for example, may contain several drinks. A listConcept · lights on your maplistA structure that stores multiple values together in a particular order: a cart’s drinks, a feed’s posts, a page of search results. Written with square brackets in Python. Other languages call essentially the same idea an array. stores multiple values together in a particular order.
In Python, lists are written using square brackets: drinks = ["latte", "flat white", "mocha"]
This list contains three strings:
"latte""flat white""mocha"
The order is preserved. The latte is first, the flat white is second, and the mocha is third.
Different programming languages may use the word array instead of list, and the concepts are closely related, although arrays and lists can have technical differences depending on the language.
At this stage, you can think of both as structures that hold several values in order.
Objects and labeled values
An order is more than a list, though. It contains several different facts that belong together:
- The customer’s name
- The total price
- Whether payment succeeded
- The drinks ordered
Programs need a way to bundle those facts and give each one a label.
Many languages use an objectConcept · lights on your mapobjectA structure that groups related values describing one thing, each with a label. In Python, the common version is a dictionary, written with curly braces. Nearly every “thing” a product manages (a user, an order, a payment) travels through code as one. or an object-like structure for this purpose. An object groups related values that describe one thing.
In Python, the structure commonly used for labeled values is called a dictionary.
A dictionary is written using curly braces:
order = {"customer": "Erik","total": 14.50,"paid": False,"drinks": ["latte", "flat white", "mocha"]}This dictionary represents one order.
The labels on the left, such as "customer" and "total", are called keys, and the information associated with each key is called its value.
The order contains four key-value pairs:
"customer"has the string value"Erik"."total"has the float value14.50."paid"has the boolean valueFalse."drinks"has a list as its value.
A value inside a structure can therefore be another structure. The order dictionary contains a list, and larger systems may contain lists of many dictionaries.
Type-spot each value the way an engineer would.
Reading the complete example
Consider the following code:
drinks = ["latte", "flat white", "mocha"]order = {"customer": "Erik","total": 14.50,"paid": False,"drinks": drinks}The first line creates a variable named drinks and associates it with a list of three strings, and the next section creates a variable named order and associates it with a dictionary containing four labeled values.
The value associated with "drinks" is the variable drinks, and Python retrieves the list stored under that variable name and places it within the order structure.
You can read the code in plain English as: create a list containing three drinks. Then create an order for Erik with a total of $14.50, mark it as unpaid, and attach the drink list.
Why these shapes matter
Strings, numbers, booleans, lists, and labeled structures appear throughout software systems.
An application may use them while processing an order, an API may send them from one system to another, and a database may store similar information using rows and columns.
Later, you will encounter JSON, a common format for exchanging data between systems. JSON frequently contains the same recognizable shapes:
- Text in quotation marks
- Numbers without quotation marks
- True-or-false values
- Lists inside square brackets
- Labeled structures inside curly braces
Learning to recognize these shapes now will make APIs, databases, and architecture diagrams easier to understand later.
The mental model to remember
A string is text, usually written inside quotation marks.
An integer is a whole number.
A float is a number that can include a decimal point.
A boolean contains one of two values: true or false.
A list, essentially what many languages call an array, holds several values in order and is commonly shown with square brackets.
An object or similar labeled structure groups related values that describe one thing. In Python, the example used in this lesson is called a dictionary and is shown with curly braces.
The punctuation provides useful clues, but the exact syntax varies across programming languages.
You should now be able to examine simple code and identify strings, numbers, booleans, lists, and labeled groups of values.
A bug report says the checkout showed “Total: 1250” for an order that should have been just $12.50. From this lesson, what's your first suspicion?
▼ answer the check to continue ▼