Skip to content
Forge Learn/Python Basics

Variables, Types & the Python REPL

5 min read

You'll learn to

  • -Create variables without declaring a type
  • -Use type() to inspect what kind of value a variable holds
  • -Recognize Python's core built-in types: int, float, str, bool, None
  • -Run Python interactively to experiment with small snippets

Every program starts with a way to remember things. In Python, that's a variable - a name bound to a value. Unlike some languages, Python never asks you to declare what type a variable will hold before you use it. You just assign it, and Python figures the rest out.

Assignment: Naming a Value

Try it yourself

The = sign is the assignment operator: it takes whatever is on the right and binds it to the name on the left. There's no "int age = 27" or "let age = 27" - no keyword announcing a type up front. Python decides what type a value is by looking at the value itself, not by anything you wrote when creating the variable.

Dynamic Typing: A Name Can Point Anywhere

This is called dynamic typing, and it has a real consequence worth internalizing early: the same variable name can be reassigned to a completely different type of value later in the same program. Python won't stop you - it just updates what the name points to.

Try it yourself

type() is the built-in function that answers "what kind of value is this, right now?" It's one of the first tools you'll reach for when a program isn't behaving the way you expect - a huge fraction of beginner bugs come down to a variable holding a different type than you assumed.

The Built-in Types You'll Use Constantly

  • -int - whole numbers, like 27 or -3, with no size limit in Python.
  • -float - numbers with a decimal point, like 3.14 or 2.0.
  • -str - text, written in quotes, like "Ada" or 'hello'.
  • -bool - exactly two values, True and False (capitalized - this trips up everyone once).
  • -None - a special value meaning "no value at all," distinct from 0, False, or an empty string.

The REPL: Python's Scratchpad

Outside of the Forge editor, the fastest way to try a one-line idea is Python's REPL (Read-Eval-Print Loop). Type "python" (or "python3") in a terminal, and you get an interactive ">>>" prompt that evaluates whatever you type and immediately shows the result - no need to save a file or run anything separately.

A REPL session - lines starting with >>> are what you type; the line below is what Python prints back.
>>> 2 + 2
4
>>> name = "Ada"
>>> name.upper()
'ADA'
>>> type(3.14)
<class 'float'>

Keep a REPL open while you read this course. Whenever you're unsure what a line of code does, the fastest way to find out is almost never to guess - it's to type it and look.

Interview Signal

What does it mean that Python is "dynamically typed," and why does it matter?

Weak Answer

"It means you don't have to write the type when you make a variable."

Strong Answer

"It means the type is checked at runtime, attached to the value rather than the variable name - so the same name can hold an int now and a string later, and Python won't catch a type mismatch until that line actually executes. That's more flexible day to day, but it also means type-related bugs (like calling a string method on a None value) surface later than they would in a statically typed language - often as a crash in production rather than a compile error."

ScaleDojo Logo
Initializing ScaleDojo