Master the Foundation with Real-World Practice
Python is one of the easiest and most powerful programming languages used todayโfrom data science to automation, it’s everywhere. Whether you’re a beginner or brushing up your knowledge, this guide walks you through the core essentials of Python with practical examples and a real-world project.
1. ๐ง Variables & Data Types #
Variables are containers used to store data. You donโt need to declare a type explicitly in Pythonโit figures it out for you!
Common Data Types: #
Type | Example | Description |
---|---|---|
int | age = 25 | Whole numbers |
float | pi = 3.14 | Decimal numbers |
str | name = "Hannan" | Text or character sequences |
bool | is_valid = True | Boolean values: True/False |
complex | z = 3 + 2j | Complex numbers (used in scientific computing) |
# Example
age = 25
height = 5.9
name = "Hannan"
is_student = True
z = 3 + 2j
2. ๐ Type Conversion & Type Checking #
Python allows dynamic typing, but you can also explicitly convert between types.
๐ Type Conversion: #
x = "10"
y = int(x) # Convert string to int
z = float(y) # Convert int to float
โ Type Checking: #
print(type(x)) # <class 'str'>
print(type(y)) # <class 'int'>
Use int()
, float()
, str()
, bool()
to convert between types.
3. ๐ฅ User Input & ๐จ Output Formatting #
Getting Input: #
name = input("Enter your name: ")
age = input("Enter your age: ")
Output Formatting: #
# Basic
print("Name:", name, "| Age:", age)
# Advanced - f-string
print(f"Hello, {name}! You are {age} years old.")
f-strings
make formatting easy and readable.
4. โ Operators in Python #
๐งฎ Arithmetic Operators #
Symbol | Meaning | Example |
---|---|---|
+ | Addition | 5 + 2 |
- | Subtraction | 5 - 2 |
* | Multiply | 5 * 2 |
/ | Divide | 5 / 2 |
// | Floor divide | 5 // 2 |
% | Modulus | 5 % 2 |
** | Power | 5 ** 2 |
๐ Comparison Operators #
Used to compare values. Returns a boolean.
5 > 3 # True
5 == 5 # True
5 != 3 # True
โ Logical Operators #
Combine multiple conditions.
x = 10
print(x > 5 and x < 20) # True
print(not x == 10) # False
๐ Assignment Operators #
Assign values to variables.
x = 5
x += 2 # x = x + 2 โ x becomes 7
5. โ String Manipulation #
Python treats strings as sequences of characters. Letโs look at the most used string methods:
๐ Common Methods: #
text = "hello python"
print(text.upper()) # HELLO PYTHON
print(text.capitalize()) # Hello python
print(text.replace("python", "world")) # hello world
print(text.split()) # ['hello', 'python']
๐ Concatenation & Formatting #
first = "Hannan"
last = "Hassan"
full_name = first + " " + last
print(f"My name is {full_name}")
๐ Indexing and Slicing #
msg = "Hello World"
print(msg[0]) # H
print(msg[-1]) # d
print(msg[0:5]) # Hello
๐ Real-World Use Case: CLI Formatted Resume #
Letโs create a basic command-line resume using Python that takes input and displays it in a nicely formatted structure.
โ Step-by-Step Code: #
print("===== CLI RESUME BUILDER =====")
print()
# Taking input from the user
name = input("Full Name: ")
email = input("Email: ")
phone = input("Phone Number: ")
summary = input("Professional Summary: ")
skills = input("Skills (comma-separated): ")
education = input("Highest Education: ")
experience = input("Most Recent Job Title: ")
# Formatting output
print("\n\n====== YOUR CLI RESUME ======\n")
print(f"๐ค Name: {name}")
print(f"๐ง Email: {email}")
print(f"๐ฑ Phone: {phone}")
print("\n๐ Summary:")
print(f"{summary}")
print("\n๐ก Skills:")
for skill in skills.split(','):
print(f" - {skill.strip()}")
print("\n๐ Education:")
print(f"{education}")
print("\n๐ผ Experience:")
print(f"{experience}")
๐ง Sample Output: #
===== CLI RESUME BUILDER =====
Full Name: Abdul Hannan
Email: hannan@example.com
Phone Number: 0300-1234567
Professional Summary: Enthusiastic Python Developer with 2 years of experience.
Skills (comma-separated): Python, SQL, APEX, Git
Highest Education: BSc in Computer Science
Most Recent Job Title: Oracle APEX Developer
====== YOUR CLI RESUME ======
๐ค Name: Abdul Hannan
๐ง Email: hannan@example.com
๐ฑ Phone: 0300-1234567
๐ Summary:
Enthusiastic Python Developer with 2 years of experience.
๐ก Skills:
- Python
- SQL
- APEX
- Git
๐ Education:
BSc in Computer Science
๐ผ Experience:
Oracle APEX Developer
๐ง Wrap Up #
This article covered:
- Variables and Data Types (like
int
,float
,str
,bool
) - Type Conversion & Checking
- User Input & Formatted Output
- Operators (Arithmetic, Logical, Comparison, etc.)
- String Manipulation
- CLI Resume Builder โ A real-world use case
โ Try It Yourself #
- Add a
save_to_file()
feature to export the resume as.txt
. - Use
datetime
to add current date or experience durations. - Convert the CLI to a GUI using libraries like
tkinter
.
Let me know if you want this as a downloadable PDF, or the next article in the Python tutorial series (like โControl Flow in Pythonโ or โFunctions & Loopsโ).