Variables & Data Types
Understanding variables and data types is the first step to becoming a programmer.
These two concepts help computers store, organize, and process information.
Think of them as:
*Variables → containers to store data
*Data Types → what kind of data stored in that container
What is a Variable?
- A variable is a named storage location in memory that holds a value.
- You can change it, update it, or use it in calculations.
* In real life:
Imagine a box with a label.
Label = variable name
Content inside = variable value
Example:
age = 18
Why Do We Need Variables?
- To store user input
- To perform calculations
- To store data from sensors
- To track score in games
- To hold login information
- To save results
- Without variables,
Computers would have no memory --- just one-time actions.
How to Declare Variables (Examples)
Python
name = "Declare"
score = 95
C
int age = 20;
float height = 5.8;
JavaScript
let city = "Chennai";
const pi = 3.14;
Different languages, different styles --- but same idea.
What Are Data Types?
A data type decides what kind of value a variable can store.
Examples:
Numbers: 18, 3.14
Text: "Hello"
True/False: True
Collection: [1, 2, 3]
Different types of data need different storage and operations.
Basic Data Types Explained Simple
Integer (Whole Numbers)
Used for whole numbers:
0, 1, 10, 500, -20
Examples:
age = 18
score = -5
Computers store integers efficiently no decimals.
Float / Double (Decimal Numbers)
Any number with a decimal:
3.14
99.99
0.5
Examples:
height = 5.7
price = 99.99
Used in:
Banking
Physics
Games
Measurements
AI calculations
String (Text Data)
Represents text — characters inside quotes.
name = "Yuva"
city = "Chennai"
Everything you type inside " "
or ' ' becomes a string.
Even numbers:
"123" → string
123 → number
Boolean (True / False)
Only two values:
- True
- False
Used for decisions:
is_logged_in = True
has_money = False
- This is the core of:
- IF conditions
- Login systems
- Game mechanics
- Sensors (on/off)
Composite / Advanced Data Types (Intro Level)
These store multiple values at once.
List / Array
- Ordered collection
- [10, 20, 30]
- Dictionary / Object
- Key → value pair
- {"name": "Yuva", "age": 18}
Tuple
Fixed group of values
(4, 6, 8)
These are powerful and used in real projects.
Comments
Post a Comment