# How to Use Python to Automate Daily Tasks: A Step-by-Step Tutorial for Beginners

Do you spend hours on repetitive tasks like renaming files, sending emails, or managing spreadsheets? With **Python automation**, you can save time and eliminate manual work by writing simple scripts.

In this guide, you’ll learn **how to automate daily tasks using Python**, even if you're a beginner. We'll cover **real-world examples**, step-by-step instructions, and useful Python libraries.

## **🔹 Why Automate Tasks with Python?**

✅ **Saves time** – Eliminate manual and repetitive work  
✅ **Boosts productivity** – Focus on important tasks instead of routine ones  
✅ **Reduces errors** – Automate tasks accurately without mistakes  
✅ **Easy to learn** – Python has beginner-friendly libraries for automation

---

## **🔹 Prerequisites**

Before we start, make sure you have:  
✔ Python installed (**Download from** [python.org](https://www.python.org/))  
✔ A basic understanding of Python syntax  
✔ An IDE (like **VS Code**, **PyCharm**, or **Jupyter Notebook**)

## **🎨 Bonus: Enhance Your UI Design with a Free Background Remover**

### [**Utilshub’s Background Remov**](https://www.utilshub.com/background-remover)[**er – Make Your UI Assets Stand**](https://www.utilshub.com/background-remover) **Out**

When designing websites or UI [components, high-quality imag](https://www.utilshub.com/background-remover)es play a **crucial role**. However, m[any designers struggle with **r**](https://www.utilshub.com/background-remover)**emoving backgrounds** to create clean, professional visuals.

That's where **Utilshub’s AI-Powered Background Remover** comes in! With just **one click**, you can:[  
✔ **Remove backgrounds from im**](https://www.utilshub.com/background-remover)**ages instantly**  
✔ **Make UI components look sleek and professional**  
✔ **Create transparent assets for web design**  
✔ **Save time on manual editing**

This diagram represents how Python automates tasks like file management, email sending, web scraping, and Excel processing.

```plaintext
          Start
            │
            ▼
   ┌─────────────────┐
   │   User Input   │  (Choose task: Files, Email, Web Scraping, Excel)
   └─────────────────┘
            │
            ▼
   ┌─────────────────┐
   │  Load Python    │  (Run the script)
   └─────────────────┘
            │
            ▼
   ┌────────────────────────┐
   │  Task Execution        │  (Perform the selected automation)
   ├────────────────────────┤
   │ - Rename files         │  
   │ - Send email           │  
   │ - Scrape web data      │  
   │ - Modify Excel files   │  
   └────────────────────────┘
            │
            ▼
   ┌─────────────────┐
   │  Task Completed │  (Save output, send confirmation)
   └─────────────────┘
            │
            ▼
          End
```

You can create a **mind map** like this:

```plaintext
        Python Automation
               │
  ┌───────────┴───────────┐
  │                       │
 File Handling      Web Scraping
  │                       │
  ├── Rename Files        ├── Extract Data
  ├── Move Files          ├── Scrape Prices
  ├── Delete Files        ├── Auto-fill Forms
  │                       │
  │                       │
 Email Automation    Excel & CSV Automation
  │                       │
  ├── Send Emails         ├── Read & Edit Data
  ├── Bulk Emails         ├── Generate Reports
  ├── Auto-Responses      ├── Automate Data Entry
```

# **🔹 Step 1: Automate File and Folder Management**

### **📌 Example: Rename Multiple Files Automatically**

If you have hundreds of files and need to rename them, Python can do it in seconds.

**🔹 Install Required Library:**

```plaintext
pip install os
```

**🔹 Python Script:**

```plaintext
import os

folder_path = "C:/Users/YourName/Documents/files"  # Change this to your folder path
for index, filename in enumerate(os.listdir(folder_path)):
    new_name = f"document_{index}.txt"  # Customize file naming pattern
    old_file = os.path.join(folder_path, filename)
    new_file = os.path.join(folder_path, new_name)
    os.rename(old_file, new_file)

print("Files renamed successfully!")
```

✅ **What it does?**

* Reads all files in a folder
    
* Renames them with a sequential number (`document_1.txt`, `document_2.txt`, etc.)
    

---

# **🔹 Step 2: Automate Sending Emails with Python**

### **📌 Example: Send Automated Emails Using Python**

You can send **emails with attachments** automatically using Python’s **smtplib** and **email** modules.

**🔹 Install Required Libraries:**

```plaintext
pip install smtplib email
```

**🔹 Python Script:**

```plaintext
import smtplib
from email.message import EmailMessage

# Email credentials
EMAIL_ADDRESS = "your_email@gmail.com"
EMAIL_PASSWORD = "your_password"

def send_email():
    msg = EmailMessage()
    msg["Subject"] = "Automated Email from Python"
    msg["From"] = EMAIL_ADDRESS
    msg["To"] = "recipient@example.com"
    msg.set_content("Hello, this is an automated email sent using Python!")

    # Send email
    with smtplib.SMTP_SSL("smtp.gmail.com", 465) as smtp:
        smtp.login(EMAIL_ADDRESS, EMAIL_PASSWORD)
        smtp.send_message(msg)

send_email()
print("Email sent successfully!")
```

✅ **What it does?**

* Logs in to **Gmail SMTP**
    
* Sends an email with a **custom subject and message**
    
* You can modify it to send emails in bulk
    

🚀 **Tip:** If you're using Gmail, enable **"Less Secure Apps"** or use an **App Password**.

---

# **🔹 Step 3: Automate Web Scraping with Python**

### **📌 Example: Extract Data from a Website**

Use Python to scrape data from websites and save it into a file.

**🔹 Install Required Library:**

```plaintext
pip install requests beautifulsoup4
```

**🔹 Python Script:**

```plaintext
import requests
from bs4 import BeautifulSoup

url = "https://example.com"  # Replace with the website URL
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")

# Extract all <h1> tags
headings = soup.find_all("h1")

for heading in headings:
    print(heading.text)
```

✅ **What it does?**

* Sends a request to a **website**
    
* Extracts all **H1 headings**
    
* Prints them in the terminal
    

🚀 **Tip:** Modify the script to scrape **articles, prices, or stock market data!**

---

# **🔹 Step 4: Automate Excel & CSV File Management**

### **📌 Example: Read and Update an Excel File**

Use Python to automate **data entry, calculations, and reports** in Excel.

**🔹 Install Required Library:**

```plaintext
pip install openpyxl pandas
```

**🔹 Python Script:**

```plaintext
import pandas as pd

# Load Excel file
df = pd.read_excel("sales_data.xlsx")

# Calculate total sales
df["Total Sales"] = df["Quantity"] * df["Price"]

# Save the updated file
df.to_excel("updated_sales_data.xlsx", index=False)

print("Excel file updated successfully!")
```

✅ **What it does?**

* Reads an **Excel file**
    
* Calculates **Total Sales** (Quantity × Price)
    
* Saves the updated file
    

🚀 **Tip:** You can automate **invoices, reports, and data analysis!**

---

# **🔹 Conclusion: What’s Next?**

Congratulations! 🎉 You’ve learned how to use Python to automate daily tasks like:  
✔ Renaming files  
✔ Sending emails  
✔ Scraping websites  
✔ Managing Excel files

🚀 **Want to Learn More?** Try automating:

* [Introduction to Machine Learning](https://blog.bytescrum.com/introduction-to-machine-learning)
    
* [Understanding DataFrames in Machine Learning: A Comprehensive Guide](https://blog.bytescrum.com/understanding-dataframes-in-machine-learning-a-comprehensive-guide)
    
* [Predicting Stock Prices Using Machine Learning and Python](https://blog.bytescrum.com/predicting-stock-prices-using-machine-learning-and-python)
    

💬 **What would you like to automate with Python?** Comment below and let’s discuss! 🚀🔥
