Variables: Your First Programming Tool
When you start learning to program, there’s one concept you encounter before anything else: variables. Every complex program, no matter how sophisticated it appears, ultimately comes down to creating and manipulating variables. In this article, we’ll explore what variables actually are, how to use them, and why they’re essential.
What Is a Variable?
The simplest way to describe a variable is as a named box for storing data. Inside this box, you can store information—numbers, text, true/false values, and more—and retrieve it whenever you need it.
Think of it like a refrigerator with labeled shelves. Each shelf has a label (“milk,” “eggs,” “cheese”), contains the appropriate item, and you retrieve from it as needed. Variables in programming work exactly the same way. The variable’s name is like the shelf label, and the value stored in the variable is the item on that shelf.

Variables and Memory
When computers store data, they write it to specific locations in RAM (memory). A variable is simply a name we give to one of these memory locations. Rather than working directly with memory addresses, variables let us refer to that data by name.
name = "Alice Johnson"
age = 28
temperature = 36.5
In the code above, name, age, and temperature each point to different memory locations, and the values "Alice Johnson", 28, and 36.5 are stored at those locations.
Why Variables Matter
1. Remembering Data
When a program receives information like a user’s name or score, it needs to store that data somewhere to use it later. Variables are that storage.
2. Making Code Readable
The variable name temperature is far clearer than the number 36.5. Good variable names reveal intent and make code easier to understand at a glance.
3. Flexibility and Reusability
You don’t have to modify your code every time the data changes. Simply update the value stored in the variable, and the rest of your program adapts automatically.
age = 28
print(age) # Output: 28
age = 29 # Update the value
print(age) # Output: 29
Declaring and Assigning Variables
Different programming languages have different ways of creating variables. Statically-typed languages (Java, C) require you to specify the type upfront, while dynamically-typed languages (Python) determine the type automatically when you assign a value.
Python (Dynamic Typing)
Python doesn’t require an explicit declaration step. The variable is created the moment you assign a value to it.
name = "Sarah Kim"
country = "South Korea"
score = 95
Java (Static Typing)
Java requires you to specify the type when creating a variable.
String name = "Sarah Kim";
String country = "South Korea";
int score = 95;
JavaScript (Dynamic Typing)
JavaScript offers three keywords for creating variables: let, const, and var.
let name = "Sarah Kim"; // Can be reassigned, function/block scope
const country = "South Korea"; // Cannot be reassigned, function/block scope
Both let and const are recommended in modern JavaScript, with const preferred when the value won’t change. The var keyword is legacy syntax and should be avoided in new code.
Variable Scope: Where Variables Can Be Used
Where a variable can be accessed depends on where it’s declared. This is called scope.
x = 10 # Global variable
def my_function():
y = 20 # Local variable inside the function
print(x) # Works: x is global
print(y) # Works
my_function()
print(x) # Works
print(y) # Error: y doesn't exist outside the function
Variables created inside a function or block are only accessible within that context. This prevents naming conflicts and makes code safer.
Data Types
The kind of data a variable holds is called its data type.
Numeric types — integers and decimals
age = 28 # Integer
height = 175.5 # Decimal
String type — text
name = "Yi Sun-sin"
message = "Hello there"
Boolean type — true or false
is_student = True
is_raining = False
List/Array type — multiple values in one variable
fruits = ["apple", "banana", "orange"]
scores = [85, 90, 78]
Naming Variables
Variable names must follow certain rules.
Rules you must follow: - Cannot start with a number (1name ✗, name1 ✓) - Cannot contain spaces (my name ✗, my_name ✓) - Cannot use special characters except underscore (user@name ✗, user_name ✓) - Avoid language keywords (if, for, class, etc.)
Naming best practices: - Use meaningful names (x ✗, user_age ✓) - Be consistent with style (stick to either snake_case or camelCase) - Keep names appropriately concise (not too long, not too short)
Variables in Practice
Here’s a simple example showing how variables are useful in real code.
# Store user information in variables
user_name = "Emma Wilson"
user_age = 25
user_city = "Toronto"
# Use stored information to generate output
print(f"{user_name} is {user_age} years old and lives in {user_city}.")
# Output: Emma Wilson is 25 years old and lives in Toronto.
# Use variables for calculations
price = 10000
quantity = 3
total = price * quantity
print(f"Total amount is {total} won.")
# Output: Total amount is 30000 won.
Without variables, you’d have to manually edit values throughout your code and re-enter numbers for every calculation. With variables, data is stored once and reused everywhere it’s needed.
Conclusion
Variables are the most fundamental tool in programming for storing and managing data. They let you access information by name instead of memory address, change values flexibly, and write code that’s easy to understand.
Everything in programming starts with creating and manipulating variables. Master them, and you’ll find learning more advanced concepts much smoother.
'코딩을 위한 용어' 카테고리의 다른 글
| [Constants] Why Const Doesn't Mean What Most Developers Think It Does (0) | 2026.05.22 |
|---|---|
| [상수] const가 객체를 지켜주지 않는 이유 (0) | 2026.05.22 |
| [변수] 냉장고처럼 이해하는 프로그래밍의 기초 (0) | 2026.05.21 |