AiTechWorlds
AiTechWorlds
Think about your kitchen for a second. You've got a mug for coffee, a bowl for soup, a wine glass for... well. The point is: different containers are built for different things. You could pour coffee into a bowl, but it'd be weird and messy. You wouldn't store olive oil in a paper bag.
Data works the same way. A phone number and a person's name are both "information" — but they're fundamentally different kinds of information. You do math with one; you display the other. If you try to add a name to a number without being explicit about what you're doing, things break.
That's why programming languages have data types: categories that tell the computer what kind of information something is, and therefore what you can do with it.
| Data Type | What It Stores | Python Name | Example |
|---|---|---|---|
| Integer | Whole numbers | int | 42, -7, 0, 1000 |
| Float | Decimal numbers | float | 3.14, -0.5, 99.99 |
| String | Text / characters | str | "Hello", "Python", "42" |
| Boolean | True or False | bool | True, False |
Notice that "42" (with quotes) is a string — the text that looks like a number. And 42 (without quotes) is an integer — the actual number. They look similar but are completely different things. You can do math with 42. You cannot do math with "42".
Integers are the counting numbers — no decimals, no fractions. They can be positive, negative, or zero.
apples = 5
temperature = -3
year = 2024
population = 8000000000
Python supports every math operation you'd expect, plus a couple of useful extras:
| Operator | Name | Example | Result |
|---|---|---|---|
+ | Addition | 10 + 3 | 13 |
- | Subtraction | 10 - 3 | 7 |
* | Multiplication | 10 * 3 | 30 |
/ | Division | 10 / 3 | 3.3333... |
// | Integer (floor) division | 10 // 3 | 3 |
% | Modulo (remainder) | 10 % 3 | 1 |
** | Exponent (power) | 10 ** 3 | 1000 |
Regular division vs integer division:
print(10 / 3) # 3.3333333333333335 — always returns a float
print(10 // 3) # 3 — drops the decimal, keeps only the whole number
print(10 % 3) # 1 — the remainder after dividing (10 = 3×3 + 1)
The modulo operator (%) sounds obscure but is incredibly useful. Want to know if a number is even or odd? number % 2 — if the result is 0, it's even; if 1, it's odd. Want to wrap around a list? Modulo does it. You'll use it more than you expect.
Floats represent numbers with decimal points — prices, measurements, percentages.
price = 19.99
temperature = 36.6
pi = 3.14159
discount = 0.15
Here's something that trips up nearly every new programmer:
print(0.1 + 0.2)
You'd expect 0.3. You actually get:
0.30000000000000004
This isn't a Python bug — it's a fundamental limitation of how all computers store decimal numbers in binary. Floats are stored as approximations. For most purposes this doesn't matter, but for money calculations (where precision is critical), be aware of it.
The fix: use round()
result = round(0.1 + 0.2, 2)
print(result) # 0.3
round(value, decimal_places) rounds a float to the number of decimal places you specify.
price = 19.987654
print(round(price, 2)) # 19.99
Any time you're working with text — names, messages, sentences, symbols — you're working with strings. In Python, strings are created by wrapping text in quotes.
first_name = "Alice"
last_name = 'Wonderland' # Single quotes work too
greeting = "Hello, World!"
empty = "" # Empty string is valid
Both single quotes ' and double quotes " create strings. The only rule: start and end with the same type.
Concatenation (joining strings with +):
first = "Hello"
second = "World"
message = first + ", " + second + "!"
print(message) # Hello, World!
Finding the length with len():
name = "Anastasia"
print(len(name)) # 9
len() counts every character, including spaces:
print(len("hello world")) # 11
Repetition with *:
print("ha" * 3) # hahaha
print("-" * 20) # --------------------
This is why we could do "=" * 30 in the first lesson — Python just repeats the string that many times.
Booleans are the simplest data type: they can only ever be one of two values — True or False. (Note the capital T and F — Python is case-sensitive.)
is_raining = True
has_umbrella = False
is_logged_in = True
On their own, they seem almost too simple to be useful. But booleans become powerful when you combine them with comparison operators — the way your program asks questions and makes decisions.
| Operator | Meaning | Example | Result |
|---|---|---|---|
== | Equal to | 5 == 5 | True |
!= | Not equal to | 5 != 3 | True |
> | Greater than | 10 > 7 | True |
< | Less than | 3 < 1 | False |
>= | Greater than or equal | 5 >= 5 | True |
<= | Less than or equal | 4 <= 3 | False |
age = 18
print(age >= 18) # True
print(age == 21) # False
print(age != 21) # True
score = 75
print(score > 50) # True
print(score < 50) # False
Notice == (double equals) checks equality. A single = is assignment (storing a value). This is a very common source of bugs for beginners — using = when you meant ==. Python will catch it with an error, so don't worry too much; just remember the distinction.
type() FunctionNot sure what type a variable is? Ask Python directly:
x = 42
y = 3.14
z = "hello"
w = True
print(type(x)) # <class 'int'>
print(type(y)) # <class 'float'>
print(type(z)) # <class 'str'>
print(type(w)) # <class 'bool'>
The type() function is your inspector — use it whenever you're not sure what you're dealing with. You'll find it especially useful when debugging.
Let's use all four types together in something realistic:
# Simple bank account summary
account_holder = "Marcus Obi" # str — name is text
account_number = 10042867 # int — whole number, no decimals
balance = 1247.83 # float — money has decimal places
is_active = True # bool — account status
# Calculations
deposit = 200.00
new_balance = balance + deposit
# Display summary
print("=" * 35)
print(" ACCOUNT SUMMARY")
print("=" * 35)
print(f"Account Holder : {account_holder}")
print(f"Account Number : {account_number}")
print(f"Current Balance: ${balance:.2f}")
print(f"After Deposit : ${new_balance:.2f}")
print(f"Account Active : {is_active}")
print("=" * 35)
Output:
===================================
ACCOUNT SUMMARY
===================================
Account Holder : Marcus Obi
Account Number : 10042867
Current Balance: $1247.83
After Deposit : $1447.83
Account Active : True
===================================
What each type is doing:
str — holding the account holder's name, displayed as textint — holding the account number (whole number, never a decimal)float — holding the balance (money always has cents)bool — flagging whether the account is active (yes/no question)Each type was chosen because it matches the nature of the data it holds. You wouldn't store a bank balance as a string, or a person's name as an integer.
| Type | Can you do math? | Can you check length? | Can you compare? |
|---|---|---|---|
int | Yes | No | Yes |
float | Yes | No | Yes |
str | Addition (joins), * (repeats) | Yes (len()) | Yes (alphabetically) |
bool | Kind of (True=1, False=0) | No | Yes |
int, float, str, and boolint — whole numbers; supports all standard math operations including // and %float — decimal numbers; watch out for floating point precision; use round() when neededstr — text wrapped in quotes; use + to join, * to repeat, len() to measurebool — only True or False; created by comparison operators (==, !=, >, etc.)type() to check what type a variable is at any timeGet this course's notes on Telegram!
Free cheat sheets, summaries & practice exercises