📘 Variables & Types: Programming Foundations
Think Socratically: if I write x = 5, what exactly is 'x'? It is not the number 5; it is a name that has been associated with the value 5.
What you’ll learn
- What Is a Variable, Really?Define a variable as a named binding between an identifier and a value stored in memory, and distinguish the name, the value, and the location.A variable is not a box that holds a value; it is a name bound to a value, and that binding is the central act of programming. The same identifier can be rebound to different values over time, while the value itself lives somewhere in memory and may be shared by several names. Separating the three ideas of name, binding, and value prevents an entire class of beginner confusion. This vocabulary carries directly into how we reason about types, assignment, and references in every later lesson.
- Types Give Values MeaningExplain that a data type defines a set of possible values together with the operations valid on them, and identify the core primitive types.A type is a contract: it fixes the set of values a piece of data can take and the operations that are legal on it. The same bits in memory can mean an integer, a character, or part of a floating-point number depending solely on the type that interprets them. The Python data model captures this by stating that an object's type determines the operations it supports and the values it can hold. Knowing the core families of types lets you predict what a value can and cannot do before you ever run the code.
- How Numbers Live in MemoryDescribe how integers are stored using two's complement and why floating-point numbers are approximate, including the consequences for arithmetic.Integers are commonly stored in fixed-width two's complement, which gives a single representation of zero and a range of negative two to the n-minus-one through positive two to the n-minus-one minus one for n bits. Floating-point numbers follow the IEEE 754 binary64 format, packing a sign, an 11-bit exponent, and a 52-bit fraction into 64 bits, which yields about 15 to 17 significant decimal digits but cannot represent most decimal fractions exactly. This is why 0.1 + 0.2 does not equal 0.3 in standard floating-point arithmetic, and why fixed-width integers can overflow. Understanding these representations turns mysterious bugs into predictable behavior.
- Static and Dynamic TypingContrast static and dynamic typing by when type information is bound and checked, and distinguish that axis from strong versus weak typing.Static typing binds a variable to a type at compile time and checks type rules before the program runs, while dynamic typing associates types with values at runtime and checks them as the program executes. A separate axis, strong versus weak typing, describes how strictly a language forbids mixing incompatible types without explicit conversion. These two axes are independent: Python is dynamically and strongly typed, while C is statically but comparatively weakly typed. Knowing where a language sits explains when its type errors appear and how much implicit coercion to expect.
- Conversion, Coercion, and Common PitfallsDifferentiate explicit type conversion from implicit coercion and diagnose the classic bugs each can cause.Type conversion changes a value from one type to another; it is explicit when the programmer requests it and implicit, called coercion, when the language performs it automatically. Coercion is convenient but can hide bugs, such as 'number plus string' producing unexpected concatenation, or a narrowing conversion silently losing precision. Comparing floating-point values for exact equality is a related classic mistake, fixed by comparing within a tolerance. Recognizing which conversions are lossless and which are lossy, and preferring explicit conversion at boundaries, is a hallmark of careful code.
- Build It: A Typed Mini-ArtifactApply variables, types, conversion, and float-safe comparison by building and reasoning about a small program artifact for your portfolio.This capstone lesson guides you to build a small, well-typed program, such as a tip-and-split calculator, that exercises every concept from the course. You will declare clearly named variables, convert string input to numbers explicitly, perform arithmetic across integer and floating-point types, and compare floats safely with a tolerance. You will also annotate your code with the type of each key value and write a short reflection identifying where conversion and rounding mattered. The finished program plus its annotations and reflection form the portfolio artifact that demonstrates your command of variables and types.
Questions this course answers
In the statement price = 19.99, which description most precisely names what 'price' is?
A variable is a name (identifier) associated with a value through a binding. The name is distinct from both the value itself and the memory location, and the binding can later change, so it is neither a permanent synonym nor merely an address.
Why do programmers usually read the '=' in count = count + 1 as 'becomes' rather than 'equals'?
Assignment performs an action: it evaluates the right side and binds the name on the left to that result. Read as algebra, count = count + 1 is a contradiction; read as 'count becomes count + 1', it correctly describes rebinding.
Which of the following is an invalid identifier in most mainstream languages, and for the stated reason?
Lexical rules in mainstream languages generally forbid identifiers that begin with a digit. Mixed case and leading underscores are allowed, and descriptiveness is a virtue, not an error.
Which statement most completely defines what a data type is?
A type specifies both the set of values data may take and the operations legal on them. Memory size is an implementation detail of some types, not the definition, and a type is independent of any variable name.
The bit pattern 01000001 is stored in memory. What determines whether it is treated as the integer 65 or the character 'A'?
Raw bits carry no inherent meaning. The type associated with the data tells the system and the reader how to interpret the identical pattern, which is why the same byte can be an integer, a character, or a fragment of a larger value.
In many strongly typed languages, why might 3 + "dog" produce an error?
Operations are defined per type. '+' means numeric addition for numbers and concatenation for strings, but no operation is defined for adding an integer to a string, so a strongly typed language reports an error rather than guessing.
Grounded in trusted sources
- Python docs, Data model / built-in types, https://docs.python.org/3/library/stdtypes.html
- MDN, JavaScript data types and variables, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures
- Java Tutorials, Primitive Data Types, https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
- CS50, Variables and types lecture materials, https://cs50.harvard.edu/
Every Wunder lesson is built from real, reputable sources — never invented.
Related courses
Wunder is a personalized learn-anything platform — tell it any topic and it builds a beautiful, fact-checked course in minutes, with narration, a knowledge check, and a college-style University track.
© 2026 Wunder Learning LLC · Terms & Privacy