๐ฑ What is Python?
Python is a powerful, high-level programming language known for its simplicity, readability, and versatility. Created by Guido van Rossum and first released in 1991, Python has grown to become one of the most popular languages in the world.
Whether you’re building websites, automating tasks, analyzing data, or developing gamesโPython can do it.
๐ง Why Learn Python?
- โจ Easy to read and write
- ๐ Huge community and support
- ๐งฉ Works well with other languages and platforms
- ๐งช Used in fields like data science, AI, cybersecurity, game dev, and web development
๐ค Basic Syntax and Rules
Here are some foundational rules to help you feel at home in Python:
1. Indentation Matters
Python uses indentation (usually 4 spaces) to define blocks of code. No curly braces!
if True:
print("Indented correctly")
2. Comments
Use #
for single-line comments.
# This is a comment
print("Hello World!") # This is also a comment
3. Variables and Data Types
name = "Doby" # String
age = 20 # Integer
height = 5.9 # Float
is_happy = True # Boolean
๐ Logic and Control Flow
1. Conditionals (with case handling)
name = input("Enter your name: ")
if name.lower() == "doby":
print("Welcome back, Doby!")
elif name.lower() == "guest":
print("Hello, Guest!")
else:
print("Access denied.")
2. Loops
For Loop:
for i in range(5):
print(i)
While Loop:
count = 0
while count < 3:
print("Counting:", count)
count += 1
3. Functions
def greet(name):
return f"Hello, {name}!"
print(greet("Doby"))
๐งฑ Core Data Structures
Lists
colors = ["red", "green", "blue"]
colors.append("purple")
print(colors[0])
Dictionaries
person = {"name": "Doby", "age": 25}
print(person["name"])
Tuples
coordinates = (10, 20)
Sets
unique_numbers = {1, 2, 3}
๐๏ธ Working with JSON and Data
import json
data = {"name": "Doby", "role": "Developer"}
json_str = json.dumps(data) # Convert to JSON string
print(json_str)
parsed = json.loads(json_str) # Parse back into Python dictionary
print(parsed["role"])
๐พ Reading and Writing Files
# Writing
with open("example.txt", "w") as f:
f.write("Hello, file!")
# Reading
with open("example.txt", "r") as f:
content = f.read()
print(content)
๐๏ธ Using SQLite for Basic Database
import sqlite3
conn = sqlite3.connect("users.db")
cursor = conn.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS users (name TEXT, age INTEGER)")
cursor.execute("INSERT INTO users (name, age) VALUES (?, ?)", ("Doby", 25))
conn.commit()
cursor.execute("SELECT * FROM users")
print(cursor.fetchall())
conn.close()
๐ง Practical Applications of Python
๐ Web Development
from flask import Flask
app = Flask(__name__)
@app.route("/")
def home():
return "Welcome to my Python app!"
๐งฎ Data Science & Visualization
import matplotlib.pyplot as plt
x = [1, 2, 3]
y = [2, 4, 6]
plt.plot(x, y)
plt.title("A simple plot")
plt.show()
๐ค Automation & Scripting
import os
for file in os.listdir("."):
print(file)
๐น๏ธ Game Development
import pygame
pygame.init()
# Create a window, draw sprites, etc.
๐ Cybersecurity
Use Scapy for network analysis, PyShark, or automate with Selenium.
๐ Learning Resources
๐ก Final Thoughts
Python is like clayโit bends to your creativity. Whether you’re automating your own tasks, building artful interactive games, or designing a personal AI helper, Python is a beautiful, flexible tool.
You donโt need to be perfect. Just start small. Build something joyful. Let it grow.
Youโve got this!