🚀 Today I Learned: Operator Overloading in Python While exploring Object-Oriented Programming in Python, I came across an interesting concept — Operator Overloading. 👉 It allows us to define how operators like "+", "-", "*" behave for our own custom objects. 💡 Simple Idea: Instead of using operators only for numbers, we can use them for our own classes too! 🔧 Example: class Number: def __init__(self, value): self.value = value def __add__(self, other): return Number(self.value + other.value) def __str__(self): return f"{self.value}" n1 = Number(10) n2 = Number(20) print(n1 + n2) # Output: 30 🔥 Here, "+" is not just adding numbers — it’s calling "__add__()" behind the scenes! 📌 Key Takeaways: ✔ Operator overloading improves code readability ✔ Uses special methods (dunder methods like "__add__") ✔ Makes objects behave like real-world entities ✔ Important concept in OOP & interviews 💭 Learning how small features like this work internally really changes the way we write code. #Python #OOP #CodingJourney #100DaysOfCode #Programming #Learning
More Relevant Posts
-
At this point, Python is starting to feel less like a language… and more like a toolkit. Today’s Python MahaRevision 🧠 Chapter 13: Advanced Python (Part 2) This chapter introduced some really powerful and practical concepts: → Virtual environments → pip freeze (managing dependencies) → Lambda functions → bin() method → format() function → map, filter, reduce It’s interesting how these tools make code shorter, cleaner, and more efficient—once you understand how to use them properly. Practice set done: Worked on applying lambda functions, transforming data using map/filter, experimenting with reduce, and managing environments and dependencies. Some concepts felt a bit abstract at first (especially map/filter/reduce)… but with practice, they started making more sense. Biggest takeaway: Better tools don’t just make coding easier—they change how you think about solving problems. Still exploring, still improving. #Python #LearningInPublic #CodingJourney #Programming #AdvancedPython
To view or add a comment, sign in
-
Day 21 of #100DaysOfLearning — Python OOP & Operator Overloading Today, I worked on building a Vector class in Python and explored how to make code more intuitive using operator overloading. What I learned: -Creating a class with attributes (x, y) -Implementing __add__() to add two vectors using + -Using __str__() to display vectors in mathematical form (like 5i + 9j) -Taking user input in custom format (5i 9j) and converting it into usable data One interesting part was handling input like: 5i 9j → converting it into numeric values using string methods like .replace() and .split() Result: I can now add two vectors like: (5i + 9j) + (1i + 2j) = (6i + 11j) This small project helped me understand how powerful Python’s magic methods are in making code cleaner and closer to real-world math. Next: Planning to explore vector operations like dot product and magnitude (important for Machine Learning) #Python #MachineLearning #100DaysOfCode #OOP #CodingJourney #LearnInPublic #SkillShikshya
To view or add a comment, sign in
-
-
🚀 Python Series – Day 2: Installing Python & Writing Your First Program Yesterday, we understood What is Python & Why it is powerful. Today, let’s take the first real step— installing Python and writing your first program 💻 🔧 Step 1: Install Python 1. Go to the official website: https://www.python.org 2. Download the latest version 3. While installing, IMPORTANT: ✔️ Check “Add Python to PATH” ▶️ Step 2: Verify Installation Open Command Prompt / Terminal and type: python --version 🧠 Step 3: Your First Python Program print("Hello, World!") 💡 What does this mean? print() → Used to display output "Hello, World!"→ Text (string) 🎯 Why is this important? This is your first step into coding. Every expert once started with this simple line. 🔥 Pro Tip: Try this: print("I am learning Python 🚀") ❓ Question for you: Have you written your first Python program yet? 👉 Comment YES / NO— I’d love to know! 📌 Tomorrow: Variables & Data Types (Most Important Topic!) #Python #DataScience #Coding #Programming #LearnPython #Beginners #Tech #MustaqeemSiddiqui
To view or add a comment, sign in
-
-
My Python Journey: Lists + Loops Today, I focused on building a strong foundation in Python with lists and loops. I practiced 10 essential problems, including: 🔹Printing all elements of a list 🔹Accessing elements at even indices 🔹Filtering even numbers 🔹Finding numbers greater than a threshold 🔹Calculating the sum of all elements (without sum()) 🔹Counting total elements (without len()) 🔹Counting numbers greater than 5 🔹Finding the smallest number (without min()) 🔹Printing a list in reverse (using loops) 🔹Creating a new list with squares of numbers 💡 Key takeaways: Loops are powerful for iteration and data manipulation Conditional checks inside loops make Python very flexible Practicing manually (without built-ins) strengthens problem-solving skills. Here’s a glimpse of my list of numbers I practiced on: nums = [14, 13, 27, 34, 20, 16, 23, 82, 49, 83] Feeling confident and ready for Day 2 challenges! 🔥 #Python #DataAnalytics #CodingJourney #100DaysOfCode #LearningByDoing #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Mastering Loops in Python 🐍 Loops in Python are essential for repeating tasks efficiently. They allow you to iterate over a sequence of elements such as lists or strings, executing the same block of code multiple times. This is incredibly useful for automating repetitive operations and processing large amounts of data in your programs. For developers, understanding loops is crucial as they form the backbone of many algorithms and data processing tasks. By mastering loops, you can write more concise and elegant code, improving the efficiency and readability of your applications. 🔎 Let's break it down step by step: 1️⃣ Initialize a counter variable 2️⃣ Set the condition for the loop to continue 3️⃣ Execute the code block inside the loop 4️⃣ Update the counter to progress through the sequence ```python # Example of a for loop in Python for i in range(5): print("Iteration", i) ``` 🚩 Pro Tip: Use `enumerate()` to access both the index and value of an item in a loop effortlessly. ❌ Common Mistake: Forgetting to update the counter variable in a loop, leading to an infinite loop and crashing your program. 🤔 What's your favorite use case for loops in Python? 🌐 View my full portfolio and more dev resources at tharindunipun.lk #PythonProgramming #DeveloperTips #CodingCommunity #LearnToCode #LoopInPython #CodeNewbie #TechTalks #ProgrammingLife
To view or add a comment, sign in
-
-
🚀 Day 12 of Python Coding Challenge 📌 Problem: Count Total Number of Characters in a File Understanding file handling is a fundamental skill in Python. Today’s task is to count the total number of characters in a given file. 💡 Approach: Open the file in read mode Read the file content Use len() to count characters 🧠 Python Code: def count_characters(file_path): try: with open(file_path, 'r') as file: content = file.read() return len(content) except FileNotFoundError: return "File not found." # Example usage file_path = "sample.txt" result = count_characters(file_path) print("Total characters in file:", result) ✅ Sample Output: Total characters in file: 12 🔍 Key Learnings: File handling using open() Using with statement for safe file operations Applying len() on strings 📢 Pro Tip: If you want to exclude spaces or newline characters, you can filter them before counting! 🔥 Keep Learning, Keep Growing! Follow along for more daily Python problems. #Python #CodingChallenge #Day12 #LearningJourney #30DaysOfCode
To view or add a comment, sign in
-
DAY 2 – #LearningInPublic (Python Basics) 🧠 Today’s Focus: My First Calculation in Python ✅ Every programming journey starts with something small — today I wrote my first Python calculation using variables and addition. Here’s what I learned: 📌 Step 1: Create Variables I stored numbers inside variables: • a = 10 • b = 10 Variables act like containers that hold values. 📌 Step 2: Perform Calculation I added both variables: sum = a + b Python calculated the result and stored it in a new variable called sum. 📌 Step 3: Print Output Finally, I displayed the result using print(): Output: 20 Wow You have done your first calculation in Python 💡 Key Concepts Learned • Variables • Assignment operator (=) • Addition operator (+) • Storing results in variables • print() function • Running first Python program This may look simple, but this is the foundation of everything in Python: Data Science Machine Learning AI Automation Web Development Every advanced system starts with basic calculations like this. Small steps. Big journey ahead. 🚀 #LearningInPublic #Python #PythonBeginner #DataScience #AI #Programming #100DaysOfCode #DeveloperJourney #MachineLearning #AIEngineering
To view or add a comment, sign in
-
Many Python I/O tutorials end at print() and open(). This one goes further. On PythonCodeCrack there's a full beginner tutorial on Python I/O that covers the ground many skip — not just how to use the tools, but why they work the way they do. What's inside: — stdin, stdout, and stderr: what they are, where they come from, and why Python didn't invent them — print() in full: sep, end, flush, and why flush=True doesn't mean your data is on disk — input() and why it always returns a string no matter what the user types — File modes r, w, a, and x — including why 'w' truncates before the first write, not during it — The three-layer CPython I/O stack (TextIOWrapper → BufferedWriter → FileIO) and how to inspect it live — PEP 393: why a single emoji in a 2 GB text file can force 4 bytes per character across the entire string — buffering=1 line-buffered mode for crash-safe log files — flush() vs os.fsync() — two entirely different operations that most tutorials treat as the same thing — Python 3.15 making UTF-8 the default on all platforms, and what that means for existing code — sys.__stdout__ vs sys.stdout, newline translation, file descriptors, and TOCTOU race conditions The tutorial includes interactive quizzes, spot-the-bug challenges, a code builder, predict-the-output exercises, a 15-question final exam, and a downloadable certificate of completion. https://lnkd.in/gbYPmYgv #Python #PythonProgramming #LearnPython #CodingEducation
To view or add a comment, sign in
-
🚀 Day 3 of #100DaysOfCode Today I practiced string operations in Python 🐍 🔍 Problem: Perform multiple operations on a string: ✔ Reverse the string ✔ Find its length ✔ Convert to uppercase ✔ Convert to lowercase 💡 Approach: Used Python’s built-in functions and slicing to solve everything in a clean way. 🐍 Code: s = "dreams" print(f"Reverse string -> {s[::-1]}") # reverse print(f"Length of string -> {len(s)}") # length print(f"String in upper format -> {s.upper()}") # uppercase print(f"String in lower format -> {s.lower()}") # lowercase 📌 Output: Reverse string -> smaerd Length of string -> 6 String in upper format -> DREAMS String in lower format -> dreams 📚 Key Learning: Slicing makes reversing very easy Python has powerful built-in string functions 💬 Small steps like this build strong fundamentals 💪 #Python #Coding #100DaysOfCode #Learning #CSE #Programming
To view or add a comment, sign in
-
-
🚀 Day 68 | Python Revision (Up to Recursion) Today I focused on revising all Python concepts up to recursion 📘 🔹 What I Revised: • Basics → variables, data types, input/output • Control statements → if-else, loops • Functions → user-defined functions, arguments • Built-in functions → len(), sum(), min(), max(), etc. • String methods → strip(), split(), replace(), join() • List & Dictionary operations • Lambda functions and functional programming basics • Recursion → factorial, list flattening 💡 Key Learning: • Revision helps in connecting all concepts together • Improved clarity on when to use loops vs recursion • Strengthened understanding of problem-solving approaches 🔥 Takeaway: 👉 Strong fundamentals come from consistent revision Consistency + Revision = Confidence 🚀 #Day68 #Python #Revision #Recursion #ProblemSolving #CodingJourney #10000Coders #PythonDeveloper #SravanKumarSir
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