Python Learning
5.74K subscribers
582 photos
2 videos
106 files
130 links
Python learning resources

Beginner to advanced Python guides, cheatsheets, books and projects.

For data science, backend and automation.
Join πŸ‘‰ https://rebrand.ly/bigdatachannels

DMCA: @disclosure_bds
Contact: @mldatascientist
Download Telegram
4 Different Patterns in Python
❀5
Python for Data Science Cheat Sheet.pdf
372.3 KB
Python for Data Science Cheatsheet
πŸ”₯3πŸ‘1
🐍 Python’s Hidden Loop Feature: for...else

πŸ‘‰ Did you know else isn't just for if statements?

Python has a unique feature almost never mentioned in beginner tutorials: you can attach an else block directly to a for or while loop.

πŸ”Ή How It Works

The else block executes ONLY if the loop finishes completely without hitting a break statement.

πŸ”Ή The Difference

❌ Traditional Way (Requires a messy flag variable):

found = False
for user in users:
if user == "Alex":
found = True
break

if not found:
print("User not found!")


βœ… Pythonic Way (Using for...else):

for user in users:
if user == "Alex":
print("User found!")
break
else:
print("User not found!")



πŸ”Ή Why Use It?

βœ”οΈ Eliminates unnecessary boolean flags (like found = True).
βœ”οΈ Cleaner, more readable syntax for search functions.
❀3πŸ‘1
python-cheat-sheet.pdf
155.6 KB
Python CheatSheet
❀2πŸ”₯2
⚑️ Python’s 1-Line Speed Booster: @lru_cache

πŸ‘‰ Did you know you can make slow Python functions run up to 100x faster by adding a single line of code?

Most tutorials skip functools.lru_cache, but it’s one of Python’s best built-in performance hacks.

πŸ”Ή How It Works

It automatically caches (remembers) the results of function calls. If you call the function with the same inputs again, Python skips the heavy computation and returns the saved answer instantly.

πŸ”Ή Code Comparison

❌ Slow (Re-calculates every single call):

def get_user_data(user_id):
# Imagine an expensive database query here
return fetch_from_db(user_id)


βœ… Very Fast (Remembers previous results):

from functools import lru_cache


@lru_cache(maxsize=128)
def get_user_data(user_id):
# Only runs ONCE per unique user_id
return fetch_from_db(user_id)



πŸ”Ή Use It to:

βœ”οΈ Speedup repetitive API calls, math calculations, or DB queries.
βœ”οΈ No third-party libraries needed (built into Python's standard library).
βœ”οΈ Prevent unnecessary server load.
❀2πŸ‘1
25 Github Repositories Every Python Developer Should Know

1. Python
The official repository of Python's source code. Dive into it to explore Python's internals or contribute to the language's development.

2. Awesome Python
A curated list of awesome Python frameworks, libraries, software, and resources. A perfect starting point for any Python developer.

3. Requests
Simplifies HTTP requests in Python. A must-have library for working with APIs and web scraping.

4. Flask
A lightweight web framework that is simple to use yet highly flexible, ideal for small to medium-sized applications.

5. Django
A high-level web framework that encourages rapid development and clean, pragmatic design for building robust web applications.

6. FastAPI
A modern web framework for building APIs with Python. Known for its speed and automatic OpenAPI documentation.

7. Pandas
Provides powerful tools for data manipulation and analysis, including support for data frames.

8. NumPy
The go-to library for numerical computations. It’s the backbone of Python’s scientific computing stack.

9. Matplotlib
A plotting library for creating static, animated, and interactive visualizations in Python.

10. Seaborn
Builds on Matplotlib and simplifies creating beautiful and informative statistical graphics.

11. Scikit-learn
A machine learning library featuring various classification, regression, and clustering algorithms.

12. TensorFlow
A powerful framework for machine learning and deep learning, supported by Google.

13. PyTorch
Another leading machine learning framework, known for its flexibility and dynamic computation graph.

14. BeautifulSoup
Simplifies web scraping by parsing HTML and XML documents.

15. Scrapy
An advanced web scraping and web crawling framework.

16. Streamlit
Makes it easy to build and share data apps using pure Python. Great for data scientists.

17. Celery
A distributed task queue library for running asynchronous jobs.

18. SQLAlchemy
A powerful ORM (Object-Relational Mapping) tool for managing database operations in Python.

19. Pytest
A robust testing framework for writing simple and scalable test cases.

20. Black
An uncompromising code formatter for Python. Makes your code consistent and clean.

21. Bokeh
For creating interactive visualizations in modern web browsers.

22. Plotly
Another library for creating interactive visualizations but with more customization options.

23. OpenCV
The go-to library for computer vision tasks like image processing and object detection.

24. Pillow
A friendly fork of PIL (Python Imaging Library), used for image processing tasks.

25. Rich
A Python library for beautiful terminal outputs with rich text, progress bars, and more.
❀3πŸ”₯2
The tell() function in Python 🐍

The tell() function returns the current position of the file pointer within the data stream. It is most often used when working with files. πŸ“‚

The function does not accept any arguments and returns an integer - the position in bytes from the beginning of the stream. πŸ”’

with open("file.txt", "rb") as f:
print(f.tell())
❀5
PYTHON SKILL ROADMAP

β”‚
β”œβ”€β”€ πŸ“ Python Basics
β”‚ β”œβ”€β”€ πŸ“ Variables & Data Types
β”‚ β”œβ”€β”€ πŸ“ Input & Output
β”‚ β”œβ”€β”€ πŸ“ Operators
β”‚ β”œβ”€β”€ πŸ“ Conditional Statements
β”‚ └── πŸ“ Loops

β”‚
β”œβ”€β”€ πŸ“ Core Python Concepts
β”‚ β”œβ”€β”€ πŸ“ Lists
β”‚ β”œβ”€β”€ πŸ“ Tuples
β”‚ β”œβ”€β”€ πŸ“ Sets
β”‚ β”œβ”€β”€ πŸ“ Dictionaries
β”‚ β”œβ”€β”€ πŸ“ Strings
β”‚ └── πŸ“ Functions

β”‚
β”œβ”€β”€ πŸ“ Problem Solving
β”‚ β”œβ”€β”€ πŸ“ Patterns
β”‚ β”œβ”€β”€ πŸ“ Number Problems
β”‚ β”œβ”€β”€ πŸ“ String Problems
β”‚ β”œβ”€β”€ πŸ“ List Problems
β”‚ β”œβ”€β”€ πŸ“ Searching
β”‚ └── πŸ“ Sorting Basics

β”‚
β”œβ”€β”€ πŸ“ Object-Oriented Python
β”‚ β”œβ”€β”€ πŸ“ Classes & Objects
β”‚ β”œβ”€β”€ πŸ“ Constructors
β”‚ β”œβ”€β”€ πŸ“ Inheritance
β”‚ β”œβ”€β”€ πŸ“ Encapsulation
β”‚ β”œβ”€β”€ πŸ“ Polymorphism
β”‚ └── πŸ“ Real OOP Examples

β”‚
β”œβ”€β”€ πŸ“ File Handling & Errors
β”‚ β”œβ”€β”€ πŸ“ Read Files
β”‚ β”œβ”€β”€ πŸ“ Write Files
β”‚ β”œβ”€β”€ πŸ“ CSV Files
β”‚ β”œβ”€β”€ πŸ“ JSON Files
β”‚ β”œβ”€β”€ πŸ“ Exception Handling
β”‚ └── πŸ“ Logging Basics

β”‚
β”œβ”€β”€ πŸ“ Python Libraries
β”‚ β”œβ”€β”€ πŸ“ NumPy Basics
β”‚ β”œβ”€β”€ πŸ“ Pandas Basics
β”‚ β”œβ”€β”€ πŸ“ Matplotlib Basics
β”‚ β”œβ”€β”€ πŸ“ Requests
β”‚ β”œβ”€β”€ πŸ“ BeautifulSoup
β”‚ └── πŸ“ Streamlit Basics

β”‚
β”œβ”€β”€ πŸ“ Automation Skills
β”‚ β”œβ”€β”€ πŸ“ File Organizer
β”‚ β”œβ”€β”€ πŸ“ Email Automation
β”‚ β”œβ”€β”€ πŸ“ Web Scraping
β”‚ β”œβ”€β”€ πŸ“ API Automation
β”‚ β”œβ”€β”€ πŸ“ Excel Automation
β”‚ └── πŸ“ Task Scheduler

β”‚
β”œβ”€β”€ πŸ“ Backend Basics
β”‚ β”œβ”€β”€ πŸ“ Flask Basics
β”‚ β”œβ”€β”€ πŸ“ FastAPI Basics
β”‚ β”œβ”€β”€ πŸ“ REST APIs
β”‚ β”œβ”€β”€ πŸ“ Databases
β”‚ β”œβ”€β”€ πŸ“ Authentication Basics
β”‚ └── πŸ“ Deploy Your API

β”‚
└── πŸ“ Portfolio Projects
β”œβ”€β”€ πŸ“ Expense Tracker
β”œβ”€β”€ πŸ“ Weather App
β”œβ”€β”€ πŸ“ Web Scraper
β”œβ”€β”€ πŸ“ URL Shortener
β”œβ”€β”€ πŸ“ Automation Bot
└── πŸ“ AI Note Summarizer

Learn the syntax first.
Then solve problems.
Then build projects.

That is how Python starts making sense.

@python_bds
❀7
🧠 return vs print() in Python

These are not interchangeable.
def add(a, b):
print(a + b)

Calling:
result = add(2, 3)

prints:
5


But:
result

is actually:
None


Now compare:
def add(a, b):
return a + b

This time:
result = add(2, 3)

gives:
result == 5

print() sends something to the screen.
return sends a value back to the caller.

That distinction becomes extremely important once functions start calling other functions.
❀6
🐍 Python Beginner Notes
❀4πŸ‘2
Python Set Methods ✍️
❀2πŸ‘1