Another Python edge case I ran into while adding support in Memphis: generator return values. The return value doesn't show up in iteration (like the `list()` builtin), but it is surfaced via `StopIteration` when you advance the generator directly (using the `next()` builtin). A short example is below. I can't say I've ever encountered this as a user, but it was a fun one to discover while implementing it.
Python Generator Return Value Edge Case in Memphis
More Relevant Posts
-
One of the most common Python mistakes I still see, especially in growing developers, is misunderstanding variable scope. It leads to code that runs but behaves unpredictably. And those are the hardest bugs to debug. Once I truly understood how Python handles local, global, and nonlocal variables, my code became easier to reason about and my debugging time dropped significantly. I wrote a short, practical guide explaining variable scope the way I wish it had been explained to me, with real examples. 👉 Read it here: https://lnkd.in/djp6HJdD #Python #LearnPython #SoftwareEngineering #DeveloperGrowth
To view or add a comment, sign in
-
I’ll admit it: early in my Python journey, I spent hours debugging code that looked fine. Functions returning the wrong value, variables mysteriously “disappearing,” and weird side effects… all because I didn’t fully understand Python variable scope. Once I got it, my code became cleaner, easier to debug, and way more predictable. I turned that hard-earned lesson into a short, practical guide that walks you through local, global, and nonlocal variables with real examples. 👉 Check it out here: https://lnkd.in/djp6HJdD If you’re serious about improving your Python fundamentals, this guide is a simple way to save hours of frustration. #Python #LearnPython #CodingTips
To view or add a comment, sign in
-
Hey all🖐️ Task1: I would like to share my Task with you.It is about "Separator in python". In python default separator is space (' ') In below video you can observe the difference that instead of space between the data we can add characters using "sep" keyword. Syntax:print(data1,data2,sep='char') Step1:Create any document in desktop. Step2:Copy the path to cmd. Step3:Write your python code in Notepad. Step4:Save your file as filename.py Step5:Open cmd and run your code as shown below. Thankyou✨
To view or add a comment, sign in
-
This session covers Python lists and tuples with a clear focus on mutability and performance. You’ll learn commonly used list methods like append(), insert(), remove(), and sort(), along with common pitfalls developers face when modifying lists. It also explains tuple immutability, when to use tuples instead of lists, and real-world examples such as coordinates and function returns. Ideal for understanding how to choose the right data structure for dynamic vs stable data.
To view or add a comment, sign in
-
🚀 Mini Project: Expense Tracker (Python Console Application) I’m excited to share my mini project — a simple Expense Tracker built using Python in VS Code. 🔹 This is a menu-driven console application that allows users to: • Add daily expenses (Date, Category, Description, Amount) • View all recorded expenses • Calculate total expenses • Exit the program safely This project helped me strengthen my understanding of Python fundamentals and improve my logical thinking while building a real-world problem-solving application. 🎯 Tools Used: Python VS Code Looking forward to feedback and suggestions to improve it further! 😊 #Python #BeginnerProject #CodingJourney #VSCode #LearningByDoing #MiniProject
To view or add a comment, sign in
-
For anyone evaluating Python config libraries, here is how I think about the landscape. I kept running into the same gap around encrypted secrets and config provenance, so I started experimenting with a project called SprigConfig to explore that space. After a few iterations, the table below reflects my current understanding. If I have mischaracterized any of these tools, especially Hydra or Pydantic, I would genuinely like to hear how others are solving this today. Open source. Feedback welcome. Quick note on Spring Python: I included it for completeness as a legacy reference point rather than a recommendation for new projects. If there are still active or modern use cases I have missed, I would genuinely like to hear about them. https://lnkd.in/g-DN9Hu9
To view or add a comment, sign in
-
-
Today’s Python lesson was on types of variables, and it made me think beyond just syntax. Different variable types exist for a reason, they help define what kind of data you’re working with, how it can be used, and what operations make sense. Getting this right early can prevent bugs, improve performance, and make your code easier to reason about. It’s interesting how something so basic becomes a foundation for writing better logic and building more reliable systems. I’m really taking my lessons one after the other. No rush!
To view or add a comment, sign in
-
-
Day 24/30 – Python Challenge 🐍 | Balanced Binary Tree Today’s problem checks whether a binary tree is height-balanced. A tree is balanced if, for every node, the height difference between its left and right subtrees is at most 1. Key ideas 💡: Use DFS (post-order traversal) to compute subtree heights If any subtree is unbalanced, stop early Return height when balanced, otherwise flag imbalance Efficient O(n) solution — each node visited once On to Day 25 🚀
To view or add a comment, sign in
-
-
✅ Day 24 of 100 — Working with Files, Directories & Paths 📂 A new skill unlocked today: file handling in Python. In this mini-project, I learned how to: - Read from and write to .txt files - Use .strip(), .replace(), and .readlines() to process content - Automate personalized letter creation The task was to take a list of names from one file and merge each into a starting_letter.txt, replacing [name] with the actual person's name—turning one template into many personalized letters in seconds. It's exciting to move beyond pure programming logic and start automating real-world tasks like mail merging. Each new concept opens another door. 🚪👨💻 #python #100DaysOfCode
To view or add a comment, sign in
-
-
I wasted months writing loops that Python already solved for me. Only later did I realize how much power is packed into Python’s built-in functions. These 10 built-ins quietly make your code: • shorter • clearer • easier to maintain 🔹 len() → count items 🔹 zip() → combine iterables 🔹 map() → apply logic 🔹 filter() → filter data 🔹 any() → check if any True 🔹 all() → check if all True 🔹 sum() → add elements 🔹 sorted() → sort values 🔹 enumerate() → index + value 🔹 range() → generate numbers If you’re learning Python: 👉 Save this 👉 Use one today 👉 Replace a loop Which one helped you the most? #Python #PythonTips #Programming #PythonDeveloper #SoftwareEngineer
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development
One would expect the list() builtin to not return a StopIteration exception in the output 😉 However, return value inside a generator does get stored in StopIteration.value - that's why you see it there.