</>
Vizly

Python Variables, Types & Type Casting

July 3, 20263 min
PythonFundamentalsPracticeBeginner

Chapter 1 of Python Fundamentals. 14 practice drills on variables, dynamic typing, casting, and truthiness. Predict the output before you run anything, that is the whole game.

How this series works

You do not get better at Python by re-reading tutorials. You get better the same way you get better at LeetCode: by attempting a problem, being wrong, and understanding why.

Every chapter here is a set of small drills. The rule for each one:

  1. Read the question. Predict the output. Say it out loud or write it down.
  2. Run it in a REPL, a notebook, or Programiz online.
  3. Then open the answer. If you were wrong, understand the why and come back to the drill in a few days.

If a drill feels easy, good. Skip ahead. This is practice, not a lecture.

Learn the concepts first

New to Python or rusty on the basics? Work through Variables and Types on learnpython.org first. Come back here to drill it in.


Before you start: variables are labels, not boxes

In Python, a variable is a name pointing at an object. It is not a box that contains a value. Most gotchas in this chapter trace back to that one sentence.

Definition

In Python, types belong to values, not to variable names. The same name can point to an int now and a string a moment later. The type is checked while the program runs, not before.


The drills

Click a question to open it. The answer stays hidden until you ask for it โ€” predict first.

14 drills. Predict first, then open the answer

Want more drills?

Fourteen questions is a warm-up, not mastery. When you finish these, let an AI quiz you with fresh ones. Copy this prompt into ChatGPT, Claude, or any assistant you like:

You are my Python drill coach. Quiz me on: variables, dynamic typing,
type casting, truthiness, == vs is, and mutable vs immutable gotchas.
 
Rules:
- Ask ONE question at a time. Show a short code snippet and ask me to
  predict the output (or the error) before running it.
- Wait for my answer. Do not reveal anything until I reply.
- If I am right, say so in one line and raise the difficulty slightly.
- If I am wrong, explain the why in 2-3 sentences, then give me a
  similar question later to check I really got it.
- Prefer tricky edge cases over textbook questions: bool("0"),
  -7 // 2, round(2.5), int("3.14"), a = b = [], NaN comparisons,
  small int caching, copy vs alias.
- Keep score. After 10 questions, list the concepts I missed so I can
  add them to my redo list.
 
Start with a medium question.

The predict-first rule matters more than the tool. Whatever generates the questions, always commit to an answer before you look.


Done?

Score yourself honestly. Any drill where your prediction was wrong goes on your redo list: come back to it in three days without peeking at the answer.

Next chapter: operators and string formatting, where 5 & 3 and 5 and 3 give different answers and f-strings do more than you think.

Edit this page on GitHubโ†—