Variables and Data Types

Last updated on 2026-10-19 | Edit this page

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, and bool.

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.

PYTHON

print("Hello world!")

OUTPUT

Hello world!

Comments


The code tells you “how”, comments tell you “why”. Everything after a # on a line is ignored by Python.

PYTHON

# This is a comment.
print("Hello world!")

OUTPUT

Hello world!
Callout

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
Callout

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: name and Name are different variables.

Data types


Every value in Python has a type. The most basic types are strings, integers, floating point numbers and booleans.

PYTHON

# String (str) - Sequence of characters
first_name = "Ada"
print(first_name)

OUTPUT

Ada

PYTHON

# Integer (int) - Whole number
age = 37
print(age)

OUTPUT

37

PYTHON

# Floating point number (float) - Fractional number
size = 1.7123
print(size)

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.

PYTHON

# Print data type
type(name)

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:

PYTHON

# The last value will be output by Jupyter Notebook
name
age

OUTPUT

37

PYTHON

# If you want to output other values, you have to use "print"
print(name)
print(age)

OUTPUT

Lovelace
37
Challenge

What type is it?

What is the type of each of the following values? Check your guesses with type().

  1. "2025"
  2. 2025
  3. 20.25
  4. False
  5. "False"
  1. str, because the value is in quotation marks
  2. int
  3. float
  4. bool
  5. str, again because of the quotation marks
Key Points
  • 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.