The
The
The function does not accept any arguments and returns an integer - the position in bytes from the beginning of the stream. 🔢
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
│
├── 📁 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
🧠
These are not interchangeable.
Calling:
prints:
But:
is actually:
Now compare:
This time:
gives:
That distinction becomes extremely important once functions start calling other functions.
return vs print() in PythonThese 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
Forwarded from Programming Quiz Channel
How does @staticmethod differ from @classmethod in Python?
Anonymous Quiz
43%
A staticmethod receives the class as its first argument, a classmethod doesn't
38%
staticmethod gets neither; classmethod automatically gets the class
14%
They behave identically
5%
staticmethod can only be used with private methods
🐍 Python Performance Optimization
Python Performance Optimization: Make Your Code Faster
Writing Python code that works is only the beginning. For real-world applications, performance matters.
Here are some techniques that can significantly improve Python performance:
⚡️ 1. Use the right data structures
Choosing a
⚡️ 2. Avoid unnecessary loops
Use built-in functions, comprehensions, and optimized libraries such as NumPy when appropriate.
⚡️ 3. Profile before optimizing
Tools like
⚡️ 4. Reduce unnecessary memory usage
Generators can process large datasets without loading everything into memory at once.
⚡️ 5. Use vectorization for data processing
NumPy operations can be much faster than manually looping through millions of values.
💡 Key principle:
Don't optimize what you haven't measured.
Python Performance Optimization: Make Your Code Faster
Writing Python code that works is only the beginning. For real-world applications, performance matters.
Here are some techniques that can significantly improve Python performance:
⚡️ 1. Use the right data structures
Choosing a
set instead of a list for frequent membership checks can dramatically reduce lookup time.⚡️ 2. Avoid unnecessary loops
Use built-in functions, comprehensions, and optimized libraries such as NumPy when appropriate.
⚡️ 3. Profile before optimizing
Tools like
cProfile and timeit help identify the actual bottlenecks instead of optimizing blindly.⚡️ 4. Reduce unnecessary memory usage
Generators can process large datasets without loading everything into memory at once.
⚡️ 5. Use vectorization for data processing
NumPy operations can be much faster than manually looping through millions of values.
💡 Key principle:
Don't optimize what you haven't measured.
❤2
🐛 This Python Bug Looks Random, But It Isn't
Look at this:
What would you expect?
Actual output:
Why? The lambdas don't store the current value of
By the time the functions are called, the loop has finished and
This is called late binding.
If you actually want each function to capture the current value:
Now:
This becomes particularly important when creating callbacks inside loops, especially in GUI code, asynchronous code, and event-driven applications.
The bug isn't in
Look at this:
functions = []
for i in range(3):
functions.append(lambda: i)
for f in functions:
print(f())
What would you expect?
0
1
2
Actual output:
2
2
2
Why? The lambdas don't store the current value of
i. They remember the variable i.By the time the functions are called, the loop has finished and
i is 2.This is called late binding.
If you actually want each function to capture the current value:
functions = []
for i in range(3):
functions.append(lambda i=i: i)
Now:
0
1
2
This becomes particularly important when creating callbacks inside loops, especially in GUI code, asynchronous code, and event-driven applications.
The bug isn't in
lambda. It's in understanding when the variable is looked up.❤4
Forwarded from Free Programming Books
📘 The Big Book of Small Python Projects
✍️ Author: Al Sweigart
🔗 Read Online
#Python #Projects
➖➖➖➖➖➖➖➖➖➖➖
📚 More free programming books → @free_programming_books_bds
Part of @bigdataspecialist community
✍️ Author: Al Sweigart
🔗 Read Online
#Python #Projects
➖➖➖➖➖➖➖➖➖➖➖
📚 More free programming books → @free_programming_books_bds
Part of @bigdataspecialist community
❤2