Debugging with print() in Python: The First Tool Every Developer Reaches For Before you learn debuggers, breakpoints, or logging frameworks, there is a simpler tool that professional developers still use every day: the debugging print statement. The idea is straightforward. When your code isn’t behaving as expected, you add temporary print() calls at strategic points to see what the program is actually doing, not what you think it’s doing. The Helsinki MOOC introduces this through a concrete example. A program calculates daily wages and should double them on Sundays. The logic looks right, but the output is wrong. The first instinct might be to re-read the code looking for the mistake. A faster approach is to let the program tell you where it’s failing. You add print statements around the suspicious section: hourly_wage = 20.0 hours = 6 day = "Sunday" daily_wages = hourly_wage * hours print("condition:", day == "sunday") if day == "sunday": print("wages before:", daily_wages) daily_wages * 2 print("wages after doubling:", daily_wages) The output reveals the condition is evaluating to False, which means the if block never runs. The program isn’t doubling anything. Now you know exactly where to look. The actual bug turns out to be a capitalisation mismatch. The input contained "Sunday" but the condition was checking for "sunday". One character difference. Without the debugging print, that could take much longer to find. This pattern scales. In a more complex program, you might not know which section is failing. Print statements let you narrow it down systematically, confirm what works, isolate what doesn’t, fix the right thing. Two things worth remembering: print statements should be removed once the bug is fixed, and they are a starting point, not the whole toolkit. But for a developer at any level, knowing how to use them well is not optional. The professionals use them too. #Python #PythonMOOC2026 #BackendDevelopment #SoftwareEngineering #LearningInPublic #UniversityOfHelsinki
Debugging with print() in Python
More Relevant Posts
-
As a beginner, not every Python bug might be in your code. Sometimes… it’s the 𝗲𝗻𝘃𝗶𝗿𝗼𝗻𝗺𝗲𝗻𝘁. --- While learning Python, I did the obvious thing: ``` 𝘱𝘪𝘱 𝘪𝘯𝘴𝘵𝘢𝘭𝘭 𝘳𝘦𝘲𝘶𝘦𝘴𝘵𝘴 ``` It worked. So I kept going. --- Then things got weird. One project worked. Another didn’t. Same library. Different behavior. Example: Project A needs: ✦ requests==2.25 Project B needs: ✦ requests==2.31 Now both exist… but not really. --- What’s actually happening? Everything is getting installed globally. One version quietly overrides the other. So the system becomes: ✦ unpredictable ✦ hard to debug ✦ dependent on hidden state --- The problem wasn’t the code. It was 𝗲𝗻𝘃𝗶𝗿𝗼𝗻𝗺𝗲𝗻𝘁 𝗰𝗼𝗻𝗳𝗹𝗶𝗰𝘁𝘀. --- This is where 𝘃𝗶𝗿𝘁𝘂𝗮𝗹 𝗲𝗻𝘃𝗶𝗿𝗼𝗻𝗺𝗲𝗻𝘁𝘀 (venv) come in. Instead of sharing everything globally: Each project gets its own isolated setup. Now the flow becomes: ✦ Create a virtual environment ✦ Install dependencies inside it ✦ Keep everything project-specific --- Think of it this way: Without venv: “𝘖𝘯𝘦 𝘨𝘭𝘰𝘣𝘢𝘭 node_modules 𝘧𝘰𝘳 𝘢𝘭𝘭 𝘱𝘳𝘰𝘫𝘦𝘤𝘵𝘴” With venv: “𝘌𝘢𝘤𝘩 𝘱𝘳𝘰𝘫𝘦𝘤𝘵 𝘩𝘢𝘴 𝘪𝘵𝘴 𝘰𝘸𝘯 𝘥𝘦𝘱𝘦𝘯𝘥𝘦𝘯𝘤𝘪𝘦𝘴” --- This way, there's: ✦ No version conflicts ✦ No “works on my machine” issues ✦ No hidden surprises --- It’s easy to skip this early on. “It’s just a small project.” “I’ll fix it later.” “Feels like extra setup.” Until things start breaking for no clear reason. --- If you’re starting with Python: Don’t skip this step. Start simple: ``` 𝘱𝘺𝘵𝘩𝘰𝘯 -𝘮 𝘷𝘦𝘯𝘷 𝘷𝘦𝘯𝘷 𝘴𝘰𝘶𝘳𝘤𝘦 𝘷𝘦𝘯𝘷/𝘣𝘪𝘯/𝘢𝘤𝘵𝘪𝘷𝘢𝘵𝘦 ``` Install what you need, then can freeze it: ``` 𝘱𝘪𝘱 𝘧𝘳𝘦𝘦𝘻𝘦 > 𝘳𝘦𝘲𝘶𝘪𝘳𝘦𝘮𝘦𝘯𝘵𝘴.𝘵𝘹𝘵 ``` And add `venv/` to your `.gitignore`. --- Because: 𝗢𝗻𝗲 𝗲𝗻𝘃𝗶𝗿𝗼𝗻𝗺𝗲𝗻𝘁. 𝗠𝘂𝗹𝘁𝗶𝗽𝗹𝗲 𝗽𝗿𝗼𝗷𝗲𝗰𝘁𝘀. That’s where things start breaking. #Python #Developers #Programming #Backend #SoftwareEngineering
To view or add a comment, sign in
-
🚀 **I thought I knew Python… until I revisited the fundamentals.** As someone already working in a technical environment, I realized something important: 👉 Strong basics = Strong future in tech So today, I went back and strengthened some **core Python concepts** that actually make code more reliable and professional. 💡 What I learned today: - How to handle errors using `try-except` - Difference between **ValueError** and **IndexError** - Why `finally` always runs (no matter what) - How to create **custom errors using `raise`** - Writing cleaner code using **shorthand if-else** - Using `enumerate()` instead of manual indexing - Setting up **virtual environments (venv)** for real projects - How Python `import` actually works - Exploring modules using `dir()` - Using the **os module** to interact with the system - Understanding **local vs global variables** --- 🔑 Key Takeaways: - Writing code is easy — writing **robust code** is a skill - Error handling is what separates beginners from professionals - Virtual environments are **non-negotiable** in real-world projects - Clean and readable code saves time (yours & others’) --- 🌍 Real-World Relevance: These concepts are not just theory: - Used in **web scraping automation** - Essential for **backend development** - Critical in **production-level systems** --- 📈 I’m actively working on improving my fundamentals to move toward **advanced development and scalable systems**. --- 💬 **Question for you:** What’s one basic concept you revisited recently that changed your understanding? 👉 Let’s grow together — Connect & Follow for more learning updates! --- #Python #WebDevelopment #LearningJourney #Coding #100DaysOfCode #CareerGrowth #Programming #Developers #TechSkills
To view or add a comment, sign in
-
-
Teach With Tech: Understanding range() in Python 🧠💡 Let’s explore a simple yet powerful concept every Python beginner should know — range(). If you’ve ever wondered how programmers make things repeat without writing the same code over and over, this is one of the go-to tools. 🔹 What is range()? range() is a built-in Python function that generates a sequence of numbers. Think of it as a smart counter that does the counting for you. 🔹 Basic Syntax range(start, stop, step) start → where counting begins stop → where it ends (this number is NOT included) step → how much it increases each time 🔹 Simple Examples ✅ Example 1: for i in range(5): print(i) Output: 0 1 2 3 4 👉 Starts from 0 by default and stops before 5. ✅ Example 2: for i in range(2, 7): print(i) Output: 2 3 4 5 6 👉 Starts from 2 and stops before 7. ✅ Example 3: for i in range(1, 10, 2): print(i) Output: 1 3 5 7 9 👉 Counts with a step of 2. 🔹 Why it matters range() helps you: - Automate repetition - Keep code clean and concise - Control loops with ease 🔹 Beginner Tip If your loop seems to “miss” the last number you expected… don’t worry 😄 👉 range() always stops BEFORE the final number. Learning small concepts like this may seem simple, but they’re the building blocks of real-world programming. Keep learning. Keep creating. 🚀 @TechCrush.pro #RisewithTechCrush #Tech4Africans #LearningwithTechCrush
To view or add a comment, sign in
-
-
Most beginners memorize Python… but never actually think like a programmer. Day 9 of my Python journey changed that. ⚡ So far, I’ve been building consistency—showing up daily, learning step by step. But today’s deep dive into dictionaries & sets flipped a switch in my brain. Here’s what clicked: 1️⃣ Dictionaries = Real-world thinking Stop seeing them as syntax. Start seeing them as relationships. Keys → Questions Values → Answers 2️⃣ Methods aren’t “extra” — they’re power tools🔧 `.get()` saved me from errors `.keys()` & `.values()` helped me think in structure, not chaos 3️⃣ Sets = Clean data, fast decisions No duplicates. No noise. Just clarity. That’s how real systems think. 💭 The challenge? At first, everything felt confusing—too many methods, too many rules. But instead of jumping ahead, I slowed down… practiced… broke things… fixed them. That’s when learning turned into understanding. 🚀 If you're learning to code, remember: Don’t rush to finish Python. Master how it thinks. 👇 Drop a comment: Are you still memorizing… or starting to understand? Let’s grow together. 💡
To view or add a comment, sign in
-
-
💭 Day 5 with Python… I started thinking like a developer. By now, my code was growing… More lines, more logic, more repetition. And somewhere in between, I had this thought: “Why am I writing the same logic again and again?” 🤔 That’s when I discovered functions. A simple idea… but a powerful one: 👉 Write once. Use anytime. So instead of repeating code, I did this: ✔ Created a function ✔ Gave it a name ✔ Reused it whenever needed And just like that… my code felt cleaner, smarter, and more organized. But the real change wasn’t in the code… 💡 It was in my thinking. I stopped asking: “How do I write this?” And started asking: 👉 “How do I design this better?” 🐍 Python is no longer just syntax and errors… It’s becoming a way of solving problems step by step. ✨ That’s the shift: From writing code → to thinking like a developer. Still learning. Still improving. But now… with a different mindset. #Python #CodingJourney #Day5 #Functions #DeveloperMindset #LearnToCode #Programming #TechJourney #Growth 🚀
To view or add a comment, sign in
-
🚀 Understanding super() in Python (with a simple clarity boost!) Many learners get confused about one question: 👉 “If we are using parent methods and variables, why don’t we always use super()?” Let’s clear this up 👇 🔷 Key Idea You use super() only when you override a method and still want to use the parent version. 🔷 Case 1: No Overriding → No super() needed class Vehicle: def show(self): print("Vehicle details") class Car(Vehicle): pass car = Car() car.show() ✅ Output: Vehicle details 👉 Python automatically checks the parent class if the method is not found in the child. 👉 This is inheritance working by default. 🔷 Case 2: Overriding → super() becomes useful class Car(Vehicle): def show(self): super().show() print("This is a car") ✅ Output: Vehicle details This is a car 👉 Now we are extending the parent method, not replacing it. 🔷 Case 3: Overriding __init__ → super() is important class Car(Vehicle): def __init__(self): super().__init__() 👉 Without super(), parent variables won’t be initialized ❌ 🔷 Simple Rule to Remember ✔ No override → Python uses parent automatically ✔ Override → Parent is hidden ✔ Use super() → To bring parent behavior back 💡 One-line takeaway super() is not for inheritance — it’s for accessing the parent implementation when you override it. This small concept makes a big difference when teaching or writing clean OOP code in Python 💻✨ #Python #OOP #Coding #Programming #Developers #Learning #TechEducation
To view or add a comment, sign in
-
-
I used to be scared of coding. Then I learned 1 concept that changed everything. Python Variables. Here's what blew my mind 🤯 Your computer has RAM — billions of tiny memory boxes. A variable is just a labeled box you control. Python That's it. That's the magic. But here's what nobody tells beginners: → 🔢 int stores whole numbers age = 20 → 💧 float stores decimals price = 9.99 → 📝 str stores text name = "Alex" → ✅ bool stores True/False is_winner = True Python figures out the type automatically. No need to declare it. Just assign and go. The workflow is simple: 1️⃣ Declare → score = 0 2️⃣ Use → print(score) 3️⃣ Update → score = 100 4️⃣ Combine → msg = "You scored: " + str(score) 5️⃣ Done → Python cleans memory for you 🎉 Why does this matter? Because instead of writing 0.18 50 times in your code — you write tax_rate = 0.18 once. Change it in one place → updates everywhere. That's reusability. That's real programming thinking. Day 1 of Python felt overwhelming. But once variables clicked? Everything else started making sense. If you're learning Python right now — you're doing the right thing. Drop a 🐍 in the comments if you're on this journey too. ♻️ Repost to help someone start their coding journey today. #Python #CodingJourney #LearnToCode #100DaysOfCode #PythonBeginner #Programming #Tech #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 I’m currently strengthening my skills in Python development, focusing on building a solid foundation in logic and clean coding practices 🐍 As part of this process, I’ve been working on: 🔹 Designing functions to solve specific problems in a structured way 🔹 Using lambda functions to simplify simple operations and write more concise code 🔹 Implementing logic to analyze and validate strings, such as detecting palindromes One of the most interesting exercises was building a function that checks whether a word is a palindrome by comparing characters from both ends toward the center: def is_palindrome(text): left = 0 right = len(text) - 1 while right >= left: if not (text[left].lower() == text[right].lower()): return False left += 1 right -= 1 return True print(is_palindrome("Racecar")) # True This type of exercise has helped me strengthen key skills such as: ✔️ Logical thinking ✔️ Index handling and control flow ✔️ Writing clean and efficient code I’ve also been applying lambda functions for simple operations in a more concise way: square = lambda x: x ** 2 print(square(2)) # 4 Understanding lambda functions has been a bit challenging, especially when deciding when to use them versus traditional functions. I’m still working on building that intuition. If you have experience with lambda functions, I’d really appreciate your insights #Python #SoftwareDevelopment #Programming #Code #ContinuousLearning
To view or add a comment, sign in
-
-
Day 6 of my Python learning journey Today I tried solving a problem that looked easy at first, but understanding the logic took some time. Problem: Two Sum Given a list of numbers and a target value, find the indices of the two numbers that add up to the target. Example: nums = [4, 5, 1, 8] target = 9 Output: [0, 1] Because 4 + 5 = 9. Code I wrote: nums = [4, 5, 1, 8] target = 9 d = {} for i in range(len(nums)): num = nums[i] comp = target - num if comp in d: print("Indices:", d[comp], i) print("Values:", nums[d[comp]], nums[i]) break d[num] = i Problems I faced while coding this: At first I tried two nested loops, which worked but felt inefficient. I was confused about why we store numbers in a dictionary. The line d[num] = i also confused me because I didn’t understand why we save the index. It also took time to understand how comp = target - num helps find the pair. What I finally understood: Instead of checking every pair, we store numbers we have already seen in a dictionary. Then we check if the required number already exists. This reduces the time complexity from O(n²) to O(n). From tomorrow we will start something different. I’m planning to build a small Python project that will take about 1 week. Tomorrow I will share the project roadmap, and then we will start with Day 1 of the project. #Python #DSA #Coding #Programming #LearningInPublic #100DaysOfCode #PythonProgramming
To view or add a comment, sign in
-
-
#7 Days of Advanced Python — Learning Beyond Basics I’ve been working with Python for quite some time now — building projects, solving problems, and exploring different concepts. But recently, I realized something. Knowing Python is one thing. Using Python efficiently in real-world workflows is something else. There are so many small things that we often ignore — tools, setup, debugging, project structure — but those are exactly the things that make a big difference when you start building seriously. So I decided to start a small 7-day challenge for myself. Every day, I’ll share one thing I’m learning that is helping me move from just “writing code” to actually “building better systems”. Not theory. Just practical improvements. #𝗗𝗮𝘆 𝟭 — 𝗨𝗽𝗴𝗿𝗮𝗱𝗶𝗻𝗴 𝗺𝘆 𝗣𝘆𝘁𝗵𝗼𝗻 𝘄𝗼𝗿𝗸𝗳𝗹𝗼𝘄 Today I explored a tool called 𝘂𝘃 — 𝗮 𝗺𝗼𝗱𝗲𝗿𝗻 𝗣𝘆𝘁𝗵𝗼𝗻 𝗽𝗮𝗰𝗸𝗮𝗴𝗲 𝗺𝗮𝗻𝗮𝗴𝗲𝗿. Until now, I was mostly using pip with virtual environments. It worked, but it often felt a bit fragmented — multiple steps, dependency issues, and sometimes inconsistent setups. Using 𝘂𝘃 felt different. It’s not just about installing packages faster, it’s about simplifying the entire workflow. What stood out to me: • Faster dependency installation • Lockfiles for reproducible environments • Simpler project setup • Cleaner and more predictable workflow What I liked most is how it removes small frictions that we usually ignore — like broken environments or “it works on my machine” problems. This made me realize something important: Improvement in development is not always about learning new concepts. Sometimes, it’s about upgrading the way you work. If you want to explore it, the official documentation is a great place to start: https://docs.astral.sh/uv/ Curious — are you still using pip for everything, or have you explored tools like uv? #Python #AdvancedPython #LearningInPublic #DevTools #SoftwareDevelopment
To view or add a comment, sign in
-
Explore related topics
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