🧠 Python Concept That Explains Class Creation Order: Class Body Execution In Python, a class body is executed like normal code 👀 🤔 The Surprise class Demo: print("Inside class") ✅ Output Inside class Wait… no object created 🤯 But code ran. 🧠 What Actually Happens When Python sees: class Demo: x = 10 It does roughly: 1️⃣ Create namespace dict 2️⃣ Execute class body 3️⃣ Store names in namespace 4️⃣ Build class object 🧪 Proof class Demo: x = 10 y = x + 5 print(Demo.y) # 15 y computed during class creation 🎯 🧒 Simple Explanation 🧸 Imagine building a toy 🧸 Before selling it: 💫 workers assemble parts inside factory. 💫 That assembly = class body execution. 💡 Why This Matters ✔ Metaclasses ✔ Descriptors ✔ Decorators ✔ ORMs ✔ Framework internals ⚡ Fun Fact List comprehensions inside class have their own scope 👀 🐍 In Python, a class isn’t just declared. 🐍 Its body actually runs 🐍 Classes are built by executing code first. #Python #PythonTips #PythonTricks #AdvancedPython #CleanCode #LearnPython #Programming #DeveloperLife #DailyCoding #100DaysOfCode
Python Class Creation Order: Execution and Namespace
More Relevant Posts
-
🧠 Python Concept That Makes Functions Remember State: Function Attributes Functions aren’t just code. They’re objects 👀 🤔 The Surprise You can attach attributes to functions. def counter(): counter.count += 1 return counter.count counter.count = 0 print(counter()) # 1 print(counter()) # 2 No class. No global variable. Still remembers state 🎯 🧠 Why This Works Because in Python: def demo(): pass print(type(demo)) # function And functions have their own __dict__. 🧒 Simple Explanation 👩🏫 Imagine a teacher 📒 She keeps a notebook 📒 Every time you ask something, she checks her notebook. 📒 That notebook = function attribute. 💡 Why This Is Powerful ✔ Lightweight state ✔ Memoization tricks ✔ Decorator helpers ✔ Cleaner than globals ✔ Interview flex 😄 ⚡ Proof print(counter.__dict__) 🐍 In Python, even functions can store data 🐍 They’re not just instructions — they’re full objects with memory. #Python #PythonTips #PythonTricks #AdvancedPython #CleanCode #LearnPython #Programming #DeveloperLife #DailyCoding #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Just put together a handy reference guide on Python’s zipfile module! 📦 Inside this Word doc you’ll find clear, ready‑to‑use code snippets for: ✅ Zipping an entire folder ✅ Extracting ZIP archives ✅ Checking if a file exists ✅ Creating compressed ZIPs (using ZIP_DEFLATED) ✅ Writing text directly into a ZIP file These examples cover the most common file compression tasks – perfect for automating backups, packaging datasets, or simplifying file transfers. Whether you're just starting with Python or you're a seasoned developer, these snippets can save you time and effort. 🐍 Feel free to download, use, and share! Let me know in the comments how you use zipfile in your own projects. 👇 #Python #Automation #Coding #DataEngineering #FileHandling #Zipfile #DeveloperTips
To view or add a comment, sign in
-
Day 3/30 – Python Challenge 🐍 Today I built: File Search Tool 🔍 🔹 What it does: Searches for files in the system by name and returns their location instantly. 🔹 What I learned: Working with file systems using os module Traversing directories using os.walk() Handling user input and search logic 🔹 Challenge: Optimizing search for large directories and handling different file paths 👉 GitHub link: https://lnkd.in/dj_FEm5j Building real-world tools step by step 🚀 #Python #CodingChallenge #LearnInPublic #100DaysOfCode #Automation #DeveloperJourney
To view or add a comment, sign in
-
🧠 Python Concept: for-else Loop Yes… Python loops can have an else block 👀 🤔 How It Works The else runs only if the loop completes normally (not if it breaks). 🧪 Example numbers = [1, 3, 5, 7] for num in numbers: if num % 2 == 0: print("Even found") break else: print("No even numbers") ✅ Output No even numbers ⚡ When break Happens numbers = [1, 3, 4, 7] for num in numbers: if num % 2 == 0: print("Even found") break else: print("No even numbers") ✅ Output Even found 🧒 Simple Explanation Imagine a teacher checking students 👩🏫 If she finds a rule-breaker → stops (no else) If she checks everyone → says “All good!” (else runs) 💡 Why This Matters ✔ Cleaner search logic ✔ Avoids extra flags ✔ Pythonic pattern ✔ Useful in real projects 🐍 Python loops can have an else block 🐍 It runs only when the loop completes without a break. 🐍 A small feature, but very powerful. #Python #PythonTips #PythonTricks #AdvancedPython #Loop #ForElse #PythonLoop #CleanCode #LearnPython #Programming #DeveloperLife #DailyCoding #100DaysOfCode
To view or add a comment, sign in
-
-
Day 78 of my Python Journey 🐍(week 11) Taking a moment to reflect on everything I’ve learned so far in my journey from beginner to now: • Basics of Python (variables, data types, type casting) • User input and string handling (slicing, methods) • Conditional statements and operators • Loops (for, while, break, continue) • Functions (built-in, user-defined, arguments, recursion) • Data structures (lists, tuples, sets, dictionaries) • List methods, set methods, dictionary methods • F-strings, docstrings, enumerate • Exception handling, custom errors, finally • Modules (import, from, as, dir) • File I/O (read, write, modes, with statement) • Map, filter, reduce, lambda functions • is vs == • Introduction to OOP • Classes and objects • Constructors • Instance vs class variables • Class methods & static methods • Getters and setters • Inheritance & access specifiers • Decorators • dict, help(), super() Still a long way to go, but consistent effort is building strong fundamentals every day. #Python #CodingJourney #LearnInPublic #Day78 #Consistency
To view or add a comment, sign in
-
🔍 Explored something interesting while practicing OOP in Python While working on a simple cricket_player class, I wasn’t trying to learn anything new — just practicing. But during that, I noticed a small but important behavior. 👉 I used: >self.scores = [] to store player scores >add_score(score) to append values >avg_score() to calculate average 💡 What I realized: >The score inside add_score(score) is just a temporary value >But self.scores is the actual storage inside the object >Every time I call add_score(), I’m not passing data around — I’m updating the object’s internal state 📌 That means: The object itself keeps evolving as methods are called #Also noticed: >Even if I pass values as parameters elsewhere, the real source of truth remains self.scores >Functions can take inputs, but what matters is what part of the object they actually use This made me think of objects not just as structures, but as state containers that change over time Just a small observation from practice, but it clarified a lot. #Python #OOP #Programming #LearningByDoing #CodingJourney
To view or add a comment, sign in
-
-
Day 48 : Python While Loops & Control Statements Today I understood while loop and its usage. Hands-on : - Today I explored while loops in Python, which are used to execute a block of code repeatedly as long as a condition remains true. - I started with the basic syntax of a while loop, understanding how it differs from a for loop by relying on conditions instead of sequences. - I then learned how to use the break statement, which allows exiting the loop immediately when a certain condition is met. - Next, I explored the continue statement, which skips the current iteration and moves to the next loop cycle without stopping the loop entirely. - Additionally, I learned about the else statement in a while loop, which executes only when the loop completes normally (i.e., not terminated by a break statement). Result : - Successfully understood how to use while loops along with break, continue, and else statements to control loop execution effectively. Key Takeaways : - While loops run as long as a condition is true. - Break is used to exit the loop early. - Continue skips the current iteration and moves to the next. - Else block executes when the loop finishes without interruption. - Proper loop control helps avoid infinite loops and improves logic building. #Python #Programming #DataAnalytics #LearningJourney #WhileLoop #CodingBasics #DataScience #BeginnerPython #AnalyticsSkills
To view or add a comment, sign in
-
-
I stop watching Python tutorial and built this game This time, I work on a simple excersize — Snake Water Gun . This project is based on a real-world problem: how user input is handled, processed, and used to make decisions in a system. Just like real applications take inputs and respond with outputs, this game follows the same logic in a simple way. 🛠 What I Used • Python • Random Module • Conditional Statements • Loops 🎯 What I Learned • How to handle user input effectively • Writing decision-based logic (if-else) • Building interactive programs • Thinking like a problem solver, not just a learner Small projects. Real understanding. 🚀 Learning in public, step by step. 💬 What should I build next? Github repo link:-https://lnkd.in/dZkfHZeG #datascientist #aiml #Python #CodingJourney #LearnInPublic #BeginnerProjects
To view or add a comment, sign in
-
🚀 Built a Python PDF Merger I created a small Python script that automatically merges multiple PDF files into a single document. The script scans a folder, detects all PDF files, and combines them into one merged PDF using the PyPDF2 library. This was a great hands-on practice with file handling and automation using Python. 🔧 Tech Used: Python, PyPDF2 You can check the full code here: https://lnkd.in/gm2pyBpb #Python #Automation #Programming #GitHub #LearningInPublic
To view or add a comment, sign in
-
Day 4 of Python was a masterclass in decision-making. I stopped writing "scripts" and started writing "logic flows." Here’s what I learned about building a resilient program: 🔹 The Power of the 'If': From simple one-way decisions to complex Nested and Multi-way (elif) structures. It’s not just about "Yes or No"; it’s about mapping out every possible fog in the road. 🔹 Indentation is Architecture: In Python, a few spaces aren't just for clean looks—they are the law. Indentation tells the computer exactly which code belongs to which decision. If your alignment is off, your logic is off. 🔹 The (Try/Except): I learned how to anticipate human error. Instead of letting the program crash when a user enters a string instead of a number, I used try/except to catch the mistake gracefully and keep the engine running. I’m training my brain to remember that = assigns a value, but == asks a question. I am slowly getting there 🙂 Day 5 is moving into the world of Functions and Iterations (Loops). I’m shifting from making decisions to automating repetitive tasks. The pieces are finally starting to click together. #Python #CodingLogic #BuildInPublic #SoftwareDevelopment #TechJourney #ProblemSolving
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