๐ก Introduction
Before creating programs or apps, you need to understand the building blocks of code.
These are the basic concepts that every programming language โ Python, Java, C++, or others โ is built upon.
In this post, youโll learn about:
- Variables
- Data types
- Input and output
- Operators
๐งฑ 1. Variables
A variable is a container used to store data.
It has a name and a value, and the value can change during program execution.
๐ฌ Think of it like a labeled box where you store something.
Example (Python):
name = "Alex"
age = 20
Here:
nameis a variable storing textageis a variable storing a number
You can later change their values:
age = 21
๐ข 2. Data Types
Data types define what kind of data a variable can store.
| Data Type | Description | Example |
|---|---|---|
| Integer (int) | Whole numbers | 10, -5 |
| Float (float) | Decimal numbers | 3.14, 2.0 |
| String (str) | Text or characters | "Hello", 'EduTech' |
| Boolean (bool) | True or False | True, False |
๐ก Each language has its own syntax, but the concept is the same.
Example (Java):
int age = 18;
double price = 12.5;
String name = "Alex";
boolean isStudent = true;
โจ๏ธ 3. Input and Output
To make programs interactive, we use:
- Input โ get data from the user
- Output โ show results to the user
Example (Python):
name = input("Enter your name: ")
print("Hello, " + name)
๐ก The program waits for you to type your name, then greets you using that input.
Example (C++):
#include <iostream>
using namespace std;
int main() {
string name;
cout << "Enter your name: ";
cin >> name;
cout << "Hello, " << name;
}
โ 4. Operators
Operators are symbols that perform operations on variables or values.
They can be arithmetic, comparison, or logical.
๐น Arithmetic Operators
| Operator | Meaning | Example |
|---|---|---|
+ | Addition | 5 + 2 = 7 |
- | Subtraction | 10 - 3 = 7 |
* | Multiplication | 4 * 2 = 8 |
/ | Division | 9 / 3 = 3 |
% | Modulus (remainder) | 10 % 3 = 1 |
๐น Comparison Operators
Used to compare two values (results in True/False).
| Operator | Example | Result |
|---|---|---|
== | 5 == 5 | True |
!= | 4 != 5 | True |
> | 7 > 3 | True |
< | 2 < 1 | False |
๐น Logical Operators
Used to combine conditions.
| Operator | Meaning | Example |
|---|---|---|
and | True if both are true | x > 5 and x < 10 |
or | True if one is true | x > 5 or x < 2 |
not | Reverses True/False | not(x > 5) |
๐ง Summary
| Concept | Description |
|---|---|
| Variable | Stores a value that can change |
| Data Type | Defines what type of data a variable holds |
| Input/Output | Communicates with the user |
| Operators | Perform calculations or comparisons |