LevelUpWith

Explore / Python from Zero: Useful Scripts for Work / Lesson 2

Lesson 2: The Interactive Prompt, Values, Types and Variables

Use the interactive prompt to try out values, see their types and store them in variables with clear names.

Free to read, no account needed. Part of Python from Zero: Useful Scripts for Work.

By the end of this level you'll be able to

  • Start the interactive prompt, try out expressions and leave it again (Python 3.13 added colour and multi-line editing to the prompt)
  • Use `type()` to tell an int, float, str, bool and None apart
  • Assign, reassign and name variables so a script reads clearly

Why a prompt before more scripts?

In Level 1 you wrote a script, saved it and ran it. That works well for finished work, but it is slow when all you want to know is "what does this line do?" For that you use the interactive prompt, also called the REPL (Read, Evaluate, Print, Loop). You type one line, Python runs it and shows you the result straight away.

If you have used spreadsheets, it works like typing a formula into a cell and seeing the answer at once. Experienced developers keep a REPL open all day for exactly this. It is the quickest way to test an idea before it goes into a script.

Starting and leaving the prompt

Open a terminal (the VS Code terminal is fine) and type python on its own. On Windows py also works if that is what you used in Level 1.

PS C:\work> python
Python 3.13.x ... on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

The >>> means Python is waiting for you. Try a few things:

>>> 2 + 3          # an expression: Python works it out...
5                  # ...and prints the result for you
>>> "invoice"      # a piece of text is a value too
'invoice'

In a script you need print() to see anything. At the prompt, Python shows the value of each expression for you. This catches a lot of beginners out: a script that contains only 2 + 3 prints nothing.

What changed in Python 3.13. Python 3.13 brought in a new default prompt:

  • Colour: the prompts and error messages (tracebacks) are in colour by default.
  • Multi-line editing: press the Up arrow and you get back a whole multi-line block, not one line at a time, and you can edit it before running it again.
  • exit and quit work on their own. Before 3.13 you had to type exit() with brackets. help works the same way.
  • F1 opens help, F2 shows your history without the output, and F3 turns on paste mode, which makes pasting a large block of code easier.

Python 3.14 went further and colours your code as you type it (syntax highlighting). If your terminal shows the colours badly, you can set the PYTHON_BASIC_REPL environment variable to go back to the old prompt.

To leave the prompt:

>>> exit           # 3.13+: no brackets needed
PS C:\work>

You can also press Ctrl+Z then Enter on Windows, or Ctrl+D on macOS and Linux, at an empty prompt.

Gotcha: if you type python at the >>> prompt you get an error, because you are already inside Python. Check which prompt you are looking at: PS C:\...> or $ is your terminal, and >>> is Python.

Every value has a type

Every value in Python has a type, which tells Python what kind of thing it is and what you can do with it. The built-in type() function tells you the type of any value. Here are the five types you will meet first:

>>> type(42)          # a whole number
<class 'int'>
>>> type(19.99)       # a number with a decimal point
<class 'float'>
>>> type("Acme Ltd")  # text in quotes: a string
<class 'str'>
>>> type(True)        # True or False: a boolean
<class 'bool'>
>>> type(None)        # "no value at all"
<class 'NoneType'>

In plain terms:

Type What it is Work example
int whole number number of rows, quantity
float decimal number a price, a percentage
str text a customer name, a file name
bool True / False "is this invoice paid?"
None nothing yet / not known a manager not yet assigned

The catch is that the type depends on how the value is written, not on what it looks like to you:

>>> type(42)
<class 'int'>
>>> type("42")       # quotes make it text, even though it looks like a number
<class 'str'>
>>> type(42.0)       # a decimal point makes it a float
<class 'float'>
>>> type(true)       # lower-case: Python doesn't recognise it
NameError: name 'true' is not defined. Did you mean: 'True'?

Why this matters at work: numbers read from files often come in as str, like "42". When a total comes out wrong, type() is the first thing to check. Note also that True, False and None start with a capital letter.

Variables: names for values

A variable is a name that points to a value. You create one with =, which means "store this under that name". It does not mean "equals" as in maths.

>>> customer = "Acme Ltd"   # create a name and point it at a value
>>> invoice_count = 12
>>> is_paid = False
>>> customer                # typing a name shows its value
'Acme Ltd'
>>> type(invoice_count)     # type() works on variables too
<class 'int'>

Think of a named cell in a spreadsheet: you refer to invoice_count and you don't have to remember that the value is in B7.

Reassigning points the same name at a new value. The old value is replaced:

>>> status = "draft"
>>> status = "sent"         # same name, new value
>>> status
'sent'
>>> status = 3              # Python allows a different type too...
>>> type(status)
<class 'int'>               # ...but this makes a script hard to follow

Python lets you change a variable's type, but in real scripts it causes confusion. Keep each name for one kind of thing.

Naming variables so the script reads clearly

The rules (break these and Python stops with an error):

  • Use letters, digits and underscores only, and don't start with a digit. report2 is fine, 2report is not.
  • No spaces or hyphens: invoice-count would be read as a subtraction.
  • Don't use Python's own keywords, such as if, for or class.
  • Capital letters matter: Total and total are two different names.

The conventions (what experienced Python programmers do):

  • Use snake_case: lower-case words joined by underscores, for example unpaid_total.
  • Choose names that describe the value: days_overdue is better than d or x2.
  • Don't reuse the names of built-in functions such as type, list or input. Python lets you do it, but afterwards the built-in no longer works.
>>> type = "invoice"     # allowed, but now type() is broken
>>> type(42)
TypeError: 'str' object is not callable

If that happens, exit and start the prompt again to get a clean session.

Exercise: check it yourself

At the prompt, create supplier_name, order_quantity, unit_price, is_approved and approved_by. Give them values of the types str, int, float, bool and None. Then run type() on each one. Check: you should see str, int, float, bool and NoneType, in that order. Next, reassign is_approved to True and type the name to confirm it changed. Then exit.

Key takeaways

  • python (or py on Windows) starts the prompt and exit leaves it. You don't need brackets from Python 3.13 on.
  • Python 3.13 added colour, multi-line editing, F1 help, F2 history and F3 paste mode. Python 3.14 added syntax highlighting.
  • At the prompt, expressions show their value without print(). In a script they don't.
  • type() tells apart int, float, str, bool and NoneType. "42" is a string, not a number.
  • = stores a value under a name, and reassigning replaces it.
  • Use clear snake_case names, and never reuse built-in names like type or list.

A 6-question knowledge check follows this lesson in the app, free and without an account.

Keep going: levels 3 and 4 are free

Create a free account to open the next two levels, save your progress and pick up where you left off. No card needed.

Next: Level 3, Numbers and Arithmetic.

Create a free account →See the whole course

More like this

  • GitHub Copilot (GH-300) Exam Prep

    Learn GitHub Copilot hands-on in the editor, in the CLI and on github.com, and work through every skill in the GH-300 study guide (skills measured as of August…

    Exam prep · GH-300 · Software & Engineering · Capable · 18 levels · 4 free · Professionally curated by levelupwith.com

  • Scaling Apps Beyond the Chat Window: Part 3, Mobile Apps, Games and Growth

    Turn your first live app into a real product. Learn to choose between web and app store apps, publish a browser game, take payments safely, run and monitor a l…

    Course · Software · Software & Engineering · Capable · 24 levels · 4 free · Professionally curated by levelupwith.com

  • Scaling Apps Beyond the Chat Window: Part 2, Online, Secure and AI-Powered

    Take one small app from your GitHub repository to a public web address. You will host it on Vercel and give it a Supabase database, sign-in and file storage, w…

    Course · Software · Software & Engineering · Capable · 16 levels · 4 free · Professionally curated by levelupwith.com

  • Scaling Apps Beyond the Chat Window: Part 1, From Prompt to Project

    Move an app you built in an AI chat onto your own computer and work on it step by step with a coding agent. Save your work with Git, keep secrets out of your c…

    Course · Software · Software & Engineering · Capable · 19 levels · 4 free · Professionally curated by levelupwith.com

  • Right Chip, Right Job: CPUs, GPUs, TPUs and Beyond

    Profile a workload, place it on a roofline and pick the processor that actually suits it, whether CPU, GPU, TPU, ASIC, inference chip, NPU, FPGA or DPU. You wi…

    Beyond the Obvious · Software & Engineering · Expert · 61 levels · 4 free · Professionally curated by levelupwith.com

  • Build Your First Website with HTML and CSS

    Start from a blank file and build a real, accessible personal or small-business website that works on phones. Each level adds to the same site, covering semant…

    Course · Software · Software & Engineering · Capable · 18 levels · 4 free · Professionally curated by levelupwith.com