Variables and Data Types
Last updated on 2026-10-19 | Edit this page
Estimated time: 20 minutes
Overview
Questions
- How do I run my first Python command?
- How can I store values in Python?
- What kinds of data can Python work with?
Objectives
- Use
print()to display values in a Jupyter notebook. - Write comments to explain code.
- Assign values to variables.
- Name and identify the basic data types
str,int,float, andbool.
First command
You can use the built-in print() function to print
Python objects, such as a string, to the Jupyter notebook output. We
will explore functions in more detail later in this lesson. The objects
that we want to print are written inside the parentheses, and these are
known as the arguments of the print()
function.
OUTPUT
Hello world!
Comments
The code tells you “how”, comments tell you “why”. Everything after a
# on a line is ignored by Python.
OUTPUT
Hello world!
Markdown cells
Besides code cells, Jupyter notebooks have Markdown cells where you can provide context for your code. You can write text in italics or bold, or even both, add headings, lists, links and much more.
Variables
A variable is a name given to a value. In Python, the =
symbol is used to assign a value to a variable. In this example, Python
assigns the value "Lovelace" to the variable
name.
PYTHON
# Variables and assignment
# Lovelace: Ada Lovelace, mathematician, wrote the first computer program
name = "Lovelace"
print(name)
OUTPUT
Lovelace
Naming variables
Variable names:
- cannot start with a digit
- cannot contain spaces, quotation marks, or other punctuation
-
may contain an underscore (typically used to separate words
in long variable names, e.g.
first_name) - are case sensitive:
nameandNameare different variables.
Data types
Every value in Python has a type. The most basic types are strings, integers, floating point numbers and booleans.
OUTPUT
Ada
OUTPUT
37
OUTPUT
1.7123
PYTHON
# Boolean (bool) - One of two values
knows_math = True
print(knows_math)
likes_gardening = False
print(likes_gardening)
OUTPUT
True
False
You can use the built-in function type() to find out the
type of a value.
OUTPUT
str
Displaying values in Jupyter
In Jupyter notebooks, you can omit the print() function
for objects, such as variables, that appear on the final line of a cell.
If the final line of a Jupyter cell includes the name of a variable, its
value will be displayed in the notebook when the cell is run. Only the
last line is shown, though:
OUTPUT
37
OUTPUT
Lovelace
37
What type is it?
What is the type of each of the following values? Check your guesses
with type().
"2025"202520.25False"False"
-
str, because the value is in quotation marks intfloatbool-
str, again because of the quotation marks
- Use
print()to display values. - Use
#to add comments that explain why the code does what it does. - Use
=to assign a value to a variable. - Basic data types are strings (
str), integers (int), floating point numbers (float), and booleans (bool). - Use
type()to find out the type of a value. - Jupyter displays the value of the last line of a cell.