Day 9 of #30DaysOfPython ✅ Today I stopped letting my code crash. Exception handling. Here's what my scripts looked like before today. You type the wrong thing, Python throws a wall of red text at you, the whole program dies, and you sit there feeling personally attacked. Today I learned how to catch those errors before they explode. Wrap the risky code in a try block, tell Python exactly what to do if something goes wrong in the except block, and your program keeps running like nothing happened. The moment that sold me: I wrote a simple division script. Without exception handling, typing 0 as the divisor crashed everything with a ZeroDivisionError. With a try/except block, it just printed "hey, you can't divide by zero" and moved on. Same error. Completely different experience. The thing that tripped me up: I was writing bare except blocks — catching every possible error without specifying which one. My mentor's voice in my head (okay, it was a Stack Overflow answer) told me that's bad practice. If you catch everything, you also catch errors you didn't know existed and hide real bugs from yourself. Always name the exception. except ValueError, except FileNotFoundError, except ZeroDivisionError. Be specific. The finally block was the other thing that clicked today. Code inside finally runs no matter what — whether the try succeeded or the except caught something. Perfect for cleanup tasks. Closing a connection. Printing a summary. Saying goodbye gracefully. What I covered today: try / except — the basic safety net Catching specific exceptions by name else block — runs only if no error occurred finally block — runs always, no matter what Raising your own errors with raise Today's mini project: a safe calculator. It handles division by zero, invalid inputs, and unknown operations — all without crashing once. Day 9 done. My code finally fails gracefully. 🎯 👇 What's the most unexpected error you've ever had to catch in Python? I want to know what's waiting for me further down this road! #Python #30DaysOfPython #ExceptionHandling #BuildInPublic #CleanCode
Python Exception Handling with Try Except Blocks
More Relevant Posts
-
Day 11/365: Finding the Smallest & Second Smallest Element in a List 🔍📉 Today I worked on a classic list problem in Python: finding the smallest and second smallest elements in a list, along with their indexes — without sorting the list. What this code does step by step: I start with a list L containing different numbers. I initialize two variables: smallest and s_smallest (second smallest) with a value larger than most of the elements in the list. I also track their positions using smallest_index and second_smallest_index. Then I loop through the list using indexes: If the current element is less than or equal to smallest, I: move the current smallest to s_smallest, update smallest with the new value, and update both indexes accordingly. Else if the current element is only smaller than s_smallest, I update just the second smallest and its index. In the end, I print both the smallest and second smallest values with their positions in the list. What I learned from this exercise: How to track not just one, but two minimum values in a single pass through the list. How important it is to maintain both the value and the index while updating. How careful initialization of variables (like smallest and s_smallest) affects the correctness of the logic. How this pattern can be extended to find top-k smallest or largest elements efficiently without sorting. Day 11 done ✅ 354 more to go. If you have ideas like handling edge cases (e.g., duplicates, negative numbers, very large lists) or finding the k-th smallest element, send them my way — I’d love to build on this next. #100DaysOfCode #365DaysOfCode #Python #LogicBuilding #Lists #Indexing #CodingJourney #LearnInPublic #AspiringDeveloper
To view or add a comment, sign in
-
-
If you’ve ever felt like type hints in Python are getting…out of hand, you’re not alone. In this talk, Carlton Gibson (Django Steering Council) breaks down a real tension: Python was designed to stay dynamic, and type hints were never meant to be mandatory. But today, many teams feel pressure to add them anyway. Consider #Django, for example: • It’s built on dynamic patterns (introspection, minimal boilerplate, etc.). • Static typing often can’t fully represent those patterns. • Adding types can increase complexity without real safety gains. • Sometimes you’re just repeating yourself to satisfy the type checker. So what’s the alternative? Don’t force typing where it doesn’t fit. Keep Python dynamic – and add types where they actually bring value. The key takeaway: Instead of rewriting frameworks like Django, build typed layers on top – keeping flexibility while adding structure where needed. Don’t think “types vs. no types.” Think about using the right tool in the right place. ▶️ Watch the full talk: https://lnkd.in/eptmtpHj #Python #Django #TypeHints #StaticTyping #WebDevelopment
To view or add a comment, sign in
-
🚀 Master Python Strings: Beyond the Basics! Ever feel like you're only using upper() and lower()? Python’s string library is massive, and knowing the right method can save you lines of code and hours of debugging. 🐍 The table below is a fantastic "at-a-glance" guide, but did you know about these powerful extras? 💡 Pro-Tips for your next script: The Joiner: .join() is the cleanest way to turn a list into a string. Forget manual loops! Global Matching: Use .casefold() instead of .lower() for internationalized text—it’s much more robust for non-English characters. The Cleaner: While the chart shows .strip(), don't forget .rsplit() if you only need to break down a string from the end. Input Validation: .isalnum() is your best friend for checking if a username or password contains only letters and numbers. Common Catch: Notice len() in the list? It’s actually a built-in function, not a method! You call it like len(text), not text.len(). Also, module is a general programming concept, not a string method. #Python #CodingTips #DataScience #WebDevelopment #PythonProgramming #CleanCode #SoftwareEngineering #LearningToCode
To view or add a comment, sign in
-
-
🔤 DAY 2/30: I CAN NOW MANIPULATE TEXT LIKE A PRO Today I learned string methods in Python - functions that transform text. 📚 WHAT I LEARNED: • .strip() - remove extra spaces (clean user input) • .upper() / .lower() - change case instantly • String slicing - grab specific parts of text [start:end] • .replace() - swap words in seconds 🛠️ PROJECT: Username Validator A program that: 1. Takes any messy username input 2. Cleans it (removes spaces, fixes case) 3. Validates length (5-15 characters) 4. Tells you if it's available 💡 BIGGEST INSIGHT: String methods don't change the original - they create a NEW string. That's why you need to save them: `name = name.strip()` 🐛 BUG I FIXED: Forgot to save the cleaned string - kept getting original. Now I know: methods RETURN values, they don't modify in place. 📂 DAY 2 CODE: https://lnkd.in/gvg2Rh6N 28 days to go. Getting stronger every day. #Python #30DaysOfCode #CodingJourney #LearnToCode
To view or add a comment, sign in
-
Today’s Python lesson was one of those “ohhh, so this is why programming feels so organized” moments. 🐍 Day 05 of my #30DaysOfPython journey was all about lists, and honestly, this topic felt like the first real step toward writing cleaner, more useful code. A list in Python is an ordered and mutable collection. It can hold different data types, and yes, it can even be empty. Here’s what I explored today: 1. Creating lists with [] and list() 2. Checking length with len() 3. Accessing items through indexing, slicing, and unpacking 4. Using in to check whether an item exists 5. Adding items with append() and insert() 6. Removing items with remove(), pop(), del, and clear() 7. Copying lists with copy() 8. Joining lists using + and extend() 9. Counting and locating items with count() and index() 10. Reversing with reverse() 11. Sorting with sort() and sorted() They are not just containers for values — they are one of the most practical ways to organize, update, combine, and manage data in Python. The fact that you can add, remove, slice, copy, reverse, and sort them makes them feel like a real data-handling tool rather than just a basic collection. Today reminded me that lists are one of the most useful structures in Python because they let you work with data in a very dynamic way. One more day, one more topic, one more layer of understanding. Github Link - https://lnkd.in/gUt9EfWs #Python #LearnPython #CodingJourney #30DaysOfPython #Programming #DeveloperJourney
To view or add a comment, sign in
-
Today’s Python topic felt like the point where code stops being one-time work and starts becoming reusable. 🐍 Day 11 of my #30DaysOfPython journey was all about the basics of function, and this one was a big reminder that good code is not just about writing more — it is about writing smarter. A function is a reusable block of code designed to do a specific task, and in Python, we define it using the def keyword. Today I explored: 1. How functions are created and called 2. How return sends values back from a function and return None when nothing is returned 3. Passing parameters and arguments 4. Passing arguments using key-value style 5. Default parameters 6. Arbitrary arguments with *args 7. Arbitrary named arguments with **kwargs What stood out to me today was how functions make code feel organized, reusable, and much easier to scale. Instead of repeating the same logic again and again, you write it once and use it wherever needed. One more day, one more topic, one more step toward writing code that is cleaner, smarter, and actually built to last. Github Link - https://lnkd.in/gUhhaW_y #Python #LearnPython #CodingJourney #30DaysOfPython #Programming #DeveloperJourney
To view or add a comment, sign in
-
If your Python scripts are making 50 API calls, synchronous code spends most of its time waiting around doing absolutely nothing. Suresh Vina has written an intro to async Python using a simple analogy: boiling a kettle and making toast at the same time. Sync code does one, then the other. Async runs both concurrently. Same two tasks: 5 seconds sync, 3 seconds async. It’s not a big deal when making breakfast. But scale that concept across dozens of API calls and the difference adds up. The Infrahub Python SDK supports both sync and async natively. Switching between them is simple. Suresh walks through the core concepts, shows side-by-side code examples, and builds up to running the same operation across multiple sites concurrently. If async Python has been sitting on your "I should learn that someday" list, now’s your chance to *get up to speed*. (See what we did there? 😉) Link in comments 👇
To view or add a comment, sign in
-
-
Today’s Python topic felt less like syntax and more like learning how code makes decisions. 🐍 Day 09 of my #30DaysOfPython journey was all about conditionals, and this one felt important because it is where Python starts reacting to situations instead of just following instructions. Conditionals help a program choose what to do based on whether something is true or false. Today I explored: 1. if — runs a block when a condition is true 2. else — runs when the condition is false 3. elif — used when there is more than one condition to check 4. shorthand if-else → code if condition else code 5. nested conditions → condition inside a condition 6. logical operators like and (both conditions needs to be true) & or (any one condition needs to be true) What stood out to me today was how much control conditionals give you. They are basically the part of Python that makes logic feel alive. One more day, one more topic, one more step toward writing code that can actually think through a situation. When you first learned conditionals, what was the trickiest part: if-else, elif, or nested conditions? Github Link - https://lnkd.in/g4_tYUDG #Python #LearnPython #CodingJourney #30DaysOfPython #Programming #DeveloperJourney
To view or add a comment, sign in
-
#Flask turns 16 today 🎉 Did you know Flask started as an April Fools’ joke by Armin Ronacher? What began as a small experiment became one of the most widely used Python web frameworks. 16 years later, it’s still powering everything from quick prototypes to production apps. 💡 About the original “Denied” microframework: Armin created “Denied” to poke fun at early microframeworks that avoided dependencies by packing everything into a single file. So he did exactly that – embedding Jinja2 and Werkzeug as a base64-encoded `.zip` inside a single Python file. A month later, the idea evolved into something real. That project became Flask – turning a joke into a framework developers still rely on today. What do you use Flask for the most?
To view or add a comment, sign in
-
-
Flask has long been my go-to for deploying ML models. It's easy to use and lightweight. Companies sometimes assume that using custom ML models means having to adopt [insert big, complicated framework here]. Maybe they'll need that down the road. Maybe. But for those first steps, Flask is the way to go. (I can already see the confused looks, so: yes, I still write code and build models! It's no longer my everyday. But it's my often-enough.)
#Flask turns 16 today 🎉 Did you know Flask started as an April Fools’ joke by Armin Ronacher? What began as a small experiment became one of the most widely used Python web frameworks. 16 years later, it’s still powering everything from quick prototypes to production apps. 💡 About the original “Denied” microframework: Armin created “Denied” to poke fun at early microframeworks that avoided dependencies by packing everything into a single file. So he did exactly that – embedding Jinja2 and Werkzeug as a base64-encoded `.zip` inside a single Python file. A month later, the idea evolved into something real. That project became Flask – turning a joke into a framework developers still rely on today. What do you use Flask for the most?
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