𝑯𝒂𝒗𝒆 𝒚𝒐𝒖 𝒆𝒗𝒆𝒓 𝒆𝒏𝒄𝒐𝒖𝒏𝒕𝒆𝒓𝒆𝒅 𝑼𝒏𝒃𝒐𝒖𝒏𝒅𝑳𝒐𝒄𝒂𝒍 𝑬𝒓𝒓𝒐𝒓 𝒘𝒉𝒊𝒍𝒆 𝒘𝒓𝒊𝒕𝒊𝒏𝒈 𝒂 𝒄𝒐𝒅𝒆 𝒊𝒏 𝒑𝒚𝒕𝒉𝒐𝒏? Last week, I learned about data structures in python and decided to work on a task that required me to write functions that will collect student IDs, Marks, Average score, student with the highest score and determine those who failed or passed. Along the way, I encountered an 𝐔𝐧𝐛𝐨𝐮𝐧𝐝𝐋𝐨𝐜𝐚𝐥 𝐄𝐫𝐫𝐨𝐫. this happed because i used a variable before assigning a value to it. An 𝐔𝐧𝐛𝐨𝐮𝐧𝐝𝐋𝐨𝐜𝐚𝐥 𝐄𝐫𝐫𝐨𝐫 occurs when python tries to access a local variable that has not yet been associated with a value. for example: 𝒅𝒆𝒇 𝑴𝒚_𝒇𝒖𝒏𝒄𝒕𝒊𝒐𝒏(): 𝒑𝒓𝒊𝒏𝒕(𝒙) 𝒙 = 10 This will raise an 𝐔𝐧𝐛𝐨𝐮𝐧𝐝𝐋𝐨𝐜𝐚𝐥 𝐄𝐫𝐫𝐨𝐫 because 𝐱 is treated as a local variable inside the function. This task helped me better understand: 🔹 Data types and iteration in python 🔹 Message error such as 𝗨𝗻𝗯𝗼𝘂𝗻𝗱𝗟𝗼𝗰𝗮𝗹 𝗘𝗿𝗿𝗼𝗿, 𝗡𝗮𝗺𝗲𝗘𝗿𝗿𝗼𝗿, and 𝗩𝗮𝗹𝘂𝗲𝗘𝗿𝗿𝗼𝗿 This task reinforced an important lesson: 𝐞𝐫𝐫𝐨𝐫𝐬 𝐚𝐫𝐞 𝐧𝐨𝐭 𝐟𝐚𝐢𝐥𝐮𝐫𝐞𝐬, 𝐭𝐡𝐞𝐲 𝐚𝐫𝐞 𝐟𝐞𝐞𝐝𝐛𝐚𝐜𝐤. still learning, still improving.🚀 👉𝑯𝒂𝒗𝒆 𝒚𝒐𝒖 𝒇𝒂𝒄𝒆𝒅 𝒕𝒉𝒊𝒔 𝒆𝒓𝒓𝒐𝒓 𝒃𝒆𝒇𝒐𝒓𝒆? 𝑺𝒉𝒂𝒓𝒆 𝒚𝒐𝒖𝒓 𝒆𝒙𝒑𝒆𝒓𝒊𝒆𝒏𝒄𝒆 𝒊𝒏 𝒕𝒉𝒆 𝒄𝒐𝒎𝒎𝒆𝒏𝒕𝒔. #Python #Datascience #Learning
Fixing UnboundLocalError in Python while Writing a Code in Pyton
More Relevant Posts
-
🧠 Python Feature That Feels Like a Cheat Code: enumerate() Most beginners write this 👇 i = 0 for item in items: print(i, item) i += 1 But Python says… why work so hard? 😌 ✅ Pythonic Way for i, item in enumerate(items): print(i, item) 🧒 Simple Explanation Imagine numbering students in a line 🧑🎓 enumerate() gives you: ✨ the number ✨ the student at the same time 🎯 💡 Why It’s Important ✔ Cleaner code ✔ Fewer bugs ✔ More readable ✔ Very common in interviews ⚡ Bonus Tip Start counting from 1: for i, item in enumerate(items, start=1): print(i, item) ✔️ Python rewards clean thinking. ✔️ If you’re manually counting in a loop… Python already has a better way 🐍✨ #Python #PythonTips #CleanCode #LearnPython #DeveloperLife #Coding
To view or add a comment, sign in
-
-
🚀 Day 29/100 | #100DaysOfCode — Python Learning Journey 🐍 Today I explored two very important file handling methods in Python: 👉 tell() and seek() — and they completely changed how I think about reading files 📄➡️🧠 Here’s what I learned today 👇 🔹 tell() — Where am I in the file? tell() helps to find the current position of the cursor inside the file. It tells us exactly where Python is reading or writing from. 🔹 seek() — Let’s move the cursor With seek(), we can move the file pointer to any position we want. This means we can re-read data, skip data, or jump to a specific part of the file. 🔹 Why this matters Now I understand how Python controls from where to read and where to write in large files — which is super useful in real projects. Small concepts, but very powerful when building real applications 💡🔥 Still learning. Still showing up. One step closer every day 💪 👉 Trust the process. Keep coding. #Python #FileHandling #tell #seek #100DaysOfCode #LearningInPublic #CodingJourney #Consistency
To view or add a comment, sign in
-
🚀 Post #351 — Learning Python the Right Way Most people can write this in Python: a = 10 But when I asked where does a actually live in memory? Silence. That’s the gap between using Python and understanding Python. 🧠 In Python, variables don’t store values. They store references to objects. a = 10 print(id(a)) 🔍 id() gives you the memory address (identity) of the object a points to. Why this matters in real systems 👇 • Explains immutability (int, str, tuple) • Prevents bugs in shared references & mutability • Helps debug weird behavior in lists, dicts, function calls • Builds a strong base for performance + memory reasoning Example that changes how you think: a = 10 b = 10 print(id(a) == id(b)) # True (integer caching) Python is doing memory optimization, not magic. If you skip internals like this, you’ll write code — but you won’t reason about it. Curiosity at the memory level is what separates script writers from engineers. 🐍 #Python #SoftwareEngineering #BackendDevelopment #LearningInPublic #ComputerScience
To view or add a comment, sign in
-
-
21th's Python Class – Built-in Functions & Utilities In a recent Python session, we explored several built-in functions that help inspect, combine, and manipulate data efficiently. 🔹 dir() & __builtins__ Used dir() to inspect available names in the current scope Learned about __builtins__ and how Python provides default functions automatically 🔹 dict.fromkeys() Created dictionaries using keys from strings Assigned default values to all keys Updated individual key values after dictionary creation 🔹 eval() & Input Handling Compared how int, float, and input() handle user input Understood how input types affect program output and behavior 🔹 zip() Combined multiple collections into: List Tuple Set Dictionary Learned how zip() pairs elements index-wise 🔹 enumerate() Added counters to collections Generated indexed data using different starting values Converted enumerated output into list, tuple, and dictionary 🔹 ASCII Operations (chr() & ord()) Converted ASCII values to characters using chr() Converted characters to ASCII values using ord() Generated alphabet lists using ASCII ranges and list comprehension This class improved my understanding of Python’s built-in power tools, making code more readable, efficient, and expressive 🚀 #Python #BuiltInFunctions #zip #enumerate #ASCII #PythonLearning #CodingPractice Pooja Chinthakayala
To view or add a comment, sign in
-
-
Python is a beautiful lie. (And this book is the truth.) 🐍 Most people love Python because it handles the "heavy lifting" for us. We call .sort() and it just works. We use a list and don’t think twice about memory. But reading “Data Structures and Algorithms in Python” by Goodrich, Tamassia, and Goldwasser": if you don’t understand the structures, you’re just driving a car without knowing how the engine works. I’m currently un-learning the "easy way" to master the "efficient way." Why this book changed my perspective: Abstract Data Types (ADTs): It’s not just about syntax; it’s about the mathematical model. The Cost of "Easy": Understanding why a simple insert(0, value) can destroy your program’s performance as data scales. Memory Management: Learning how Python actually handles dynamic arrays under the hood. I’m no longer just writing code that runs. I’m learning to write code that scales. If you're a Python dev, are you relying on the language to be smart for you, or do you know exactly what your code is doing to the CPU? hashtag #Python hashtag #SoftwareEngineering hashtag #DataStructures hashtag #Algorithms hashtag #ComputerScience hashtag #DeepLearning
To view or add a comment, sign in
-
Most Python problems don’t fail because of logic. They fail because of how we expect Python to behave. We ask Python to give us everything.... All rows. All values. All results ....right now. And Python quietly asks a better question: What if you only took what you need? That’s where a different way of thinking begins. Generators don’t rush. They don’t store. They don’t panic about size. They move forward, one step at a time. When data grows, when files get heavy, when performance starts to matter this mindset changes everything. Python doesn’t reward clever tricks. It rewards calm, intentional thinking. And the day you realise that, your code stops feeling busy and starts feeling clean. For those who enjoy learning concepts this way, I’ve shared my Python learning notes and resources on Topmate. https://lnkd.in/gasgBQ6k #Python
To view or add a comment, sign in
-
Today’s Python focus was 𝗠𝗼𝗱𝘂𝗹𝗲𝘀. I worked on understanding how Python lets you organize code into reusable files instead of writing everything in one script. 𝗪𝗵𝗮𝘁 𝗜 𝗽𝗿𝗮𝗰𝘁𝗶𝗰𝗲𝗱 𝘁𝗼𝗱𝗮𝘆: • Importing built in modules like math and calendar • Using functions from the math module such as sqrt() and ceil() • Working with the calendar module to generate month level calendars • Creating a custom module to store reusable functions • Importing and using functions from a user defined module • Separating logic into different files for better structure and readability 𝗞𝗲𝘆 𝘁𝗮𝗸𝗲𝗮𝘄𝗮𝘆𝘀: • Modules help break large programs into smaller, manageable pieces • Built in modules save time and prevent rewriting common logic • Custom modules make code reusable across multiple scripts • Organizing functions into modules improves maintainability Working with modules made it clear how real Python projects are structured. Code is written once, organized properly, and reused when needed. If you are learning Python, are you already using modules in your practice or still keeping everything in a single file? #Python #PythonLearning #PythonModules #ProgrammingBasics #LearningInPublic #DataAnalytics #Upskilling
To view or add a comment, sign in
-
✨ Demystifying Python Strings for Beginners ✨ When I first started coding, strings felt deceptively simple—just text in quotes, right? But they’re the backbone of so many programs: storing names, messages, and even entire datasets. Here’s a quick snapshot of what you can do with strings in Python: 🔗 Concatenation: "Hello " + "World" → Hello World 📏 Length: len("Python") → 6 🎯 Indexing: "Python"[0] → P ✂️ Slicing: "Python"[1:4] → yth 🔠 Uppercase: "hello".upper() → HELLO 🔡 Lowercase: "HELLO".lower() → hello 💡 Strings aren’t just text—they’re powerful tools for manipulating and presenting information. I created this simple visual to help beginners see how strings work in action. If you’re starting your Python journey, mastering strings is a great first step toward building confidence with code. 👉 What’s the first string operation you learned that made you feel like a “real coder”? #Python #CodingForBeginners #LearnToCode #DataScience #EducationThroughStorytelling
To view or add a comment, sign in
-
-
🚀 Python Cheat Sheet for Beginners (Save This ✅) If you’re starting Python and feeling overwhelmed, this one-page cheat sheet is your quickest roadmap 🧠✨ It covers all the basics you need to start coding confidently 👇 ✅ Variables & Data Types ✅ Operators ✅ Loops (for / while) ✅ Conditional Statements ✅ Functions + Lambda ✅ Lists, Tuples, Sets, Dictionaries ✅ Exception Handling ✅ File Handling ✅ Useful Built-in Functions 📌 Best part? It’s super beginner-friendly and perfect for revision before coding practice or interviews. 💡 Pro Tip: Don’t just read it—pick 1 topic daily and write 5 lines of code to apply it. That’s how you grow fast 💯 🔖 Save this post so you can revisit anytime. #Python #PythonProgramming #LearnPython #Coding #Programming #DataScience #MachineLearning #AI #Students #Placements #SoftwareDevelopment #TechSkills #CareerGrowth #BeginnerFriendly
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
I love this sentence "errors are not failures, they are feedback". Well done, Isah MOHAMMED