Part 2: Core Programming Concepts

1. Variables & Data Types

Variables: labelled boxes for your data

A variable is a named place in the computer's memory where your program stores a value it needs to remember. The clearest way to picture it is a labelled box: the label is the variable's name, and whatever you put inside is its value. When you want the value later, you refer to the box by its label rather than its physical location.

age (label) 30 the value inside the box use the name to read it

Declaration and assignment

Two things happen when you create a variable. Declaration brings the name into existence; assignment places a value in it using the assignment operator =. Read = as "gets" or "becomes", never as mathematical equality.

age = 30            # create 'age', put 30 in it
price = 19.99       # a decimal number
name = "Ada"        # a piece of text
is_active = True     # a yes/no value

age = age + 1       # read 30, add 1, store 31 back

The last line shows why = is not equality: age = age + 1 is nonsense as maths, but as an instruction it means "take the current value, add one, and store the result back in the same box." After it runs, age holds 31.

Data types

Every value has a data type — a category that tells the computer what the value is and what you may do with it. You can add two integers, but "adding" two booleans makes no sense. Types also decide how much memory a value needs and how it is stored. The core types nearly every language shares are:

TypeStoresExample valuesTypical use
IntegerWhole numbers-4, 0, 42, 1000Counts, ages, quantities, indexes
FloatNumbers with a fractional part3.14, -0.5, 19.99Prices, measurements, averages
StringText (a sequence of characters)"hello", "Ada", "Z"Names, messages, labels
BooleanOne of two truth valuesTrue, FalseFlags, conditions, on/off state
Null / None"No value at all"None, null, nilMissing or not-yet-set data

Static vs dynamic typing

Languages differ in when they check types. In statically typed languages (Java, C#) you state a variable's type up front and it cannot change. In dynamically typed languages (Python, JavaScript) a variable simply takes the type of whatever you assign, and that can change as the program runs. Both styles track types; they just enforce them at different moments.

Naming variables well

Choose names that say what the value means: total_price beats tp, and user_count beats x. Good names turn code into something a human can read like a sentence. Most languages require names to start with a letter, allow letters, digits and underscores, and are case-sensitive — so Age and age are two different boxes.

Key idea: a variable is a named, re-usable container; its type describes the kind of value it holds and the operations that value supports.