Day 33 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to implement a custom version of the len() function. Instead of using Python’s built-in len() function, I created my own function to count the number of elements in an iterable. What the program does: • Takes any iterable as input (list, string, tuple, etc.) • Iterates through each element • Counts elements one by one • Returns the total length How the logic works: 1)A function manual_len(iterable) is defined 2)A variable count is initialized to 0 3)The program loops through each element in the iterable 4)For every element, the counter is incremented by 1 5)After the loop ends, the final count is returned Example: List:[1, 2, 3, 4, 5] Output: Length = 5 String: "Hello, Colab!" Output: Length = 13 Tuple: (10, 20, 30) Output: Length = 3 Why this is useful: – Helps understand how built-in functions work internally – Demonstrates iteration over different data types – Strengthens understanding of iterables in Python Key learnings from Day 33: – Implementing built-in functionality manually – Working with iterables in Python – Understanding loops and counters – Strengthening Python fundamentals #100DaysOfCode #Day33 #Python #PythonProgramming #Algorithms #ProblemSolving #CodingPractice #LearnByDoing #ProgrammingJourney #DeveloperGrowth #ComputerScience #InterviewPrep #BTech #CSE #AIandML #VITBhopal #TechJourney
Implementing Custom len() Function in Python
More Relevant Posts
-
🚀 Mastering loops in Python: From beginner to pro! 🐍 Looping in Python is a powerful technique to perform repetitive tasks efficiently. It allows you to iterate over a sequence of elements and execute the same block of code multiple times. For developers, mastering loops is essential as it helps in automating tasks, processing large datasets, and improving code readability. 🛠️ Let's break it down: 1️⃣ Initialize a counter variable 2️⃣ Set the loop condition 3️⃣ Execute the code block 4️⃣ Update the counter variable ```python for i in range(5): print("Iteration:", i) ``` 🚩 Pro Tip: Use a `break` statement to exit a loop prematurely when a certain condition is met. ❌ Common mistake: Forgetting to increment the counter variable can result in an infinite loop. 🤔 What's your favorite use case for loops in Python? Share in the comments below! 💬 🌐 View my full portfolio and more dev resources at tharindunipun.lk #PythonProgramming #LearnToCode #CodeNewbie #DeveloperTips #PythonLoops #CodingJourney #TechSkills #CodeWithPurpose
To view or add a comment, sign in
-
-
🚀 Day 33 of My Python Full-Stack Journey 🐍 Today I learned about the Scope of Variables in Python. Variable scope determines where a variable can be accessed within a program. Understanding scope helps in writing cleaner, more organized, and error-free code. 🔹 Types of Variable Scope in Python: • Local Scope – Variables defined inside a function and accessible only within that function. • Global Scope – Variables defined outside functions and accessible throughout the program. • Enclosing Scope – Variables in the outer function that can be accessed by nested functions. • Built-in Scope – Predefined names in Python that are always available (like print(), len(), etc.). 🔹 What I practiced today: • Creating and using local and global variables • Understanding how variables behave inside functions • Learning the LEGB rule (Local, Enclosing, Global, Built-in) • Writing programs to see how scope affects variable access Learning variable scope helps avoid conflicts between variables and improves code readability. Step by step, I’m building a stronger foundation in Python programming. 💻✨ #Python #PythonLearning #FullStackJourney #CodingJourney #LearnPython #DeveloperJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Ever wondered how to efficiently use loops in Python? Let's dive in and unravel the power of Python loops! 🐍 Python loops are used to iterate over sequences like lists, tuples, and dictionaries, executing the same block of code repeatedly. This simplifies tasks like calculations, data processing, and repetitive actions in your programs. Developers benefit greatly from mastering loops as they streamline code, improve efficiency, and help automate repetitive tasks. By understanding how loops work, developers can write cleaner code, reduce errors, and enhance their problem-solving skills. Plus, loops are fundamental in programming and are widely used in various applications. Step by Step Breakdown: 1. Initialize a list of items. 2. Use a "for" loop to iterate over each item. 3. Perform an action on each item within the loop. 💡 Pro Tip: Remember to choose the appropriate loop (for or while) based on the specific task and data structure you are working with for optimal performance and readability. ⚠️ Common Mistake Alert: Forgetting to update the loop control variable correctly can lead to infinite loops, causing your program to hang or crash. 🤔 What's your favorite application of loops in Python? Share with us in the comments below! 🌐 View my full portfolio and more dev resources at tharindunipun.lk #PythonLoops #CodeEfficiency #Programming101 #DeveloperTips #AutomationInCoding #LearnToCode #PythonProgramming #TechSkills #ProblemSolving #CodeMastery
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
-
-
A tricky Python concept 🔍 ✅ Why does this work: t = (1, 2, [3, 4]) t[2].append(5) ➡️ After this operation, the tuple becomes: t = (1, 2, [3, 4, 5]) ❌ But this fails: t[0] = 10 🔹 Explanation In Python, tuples are immutable, meaning their structure cannot be changed. However, they can contain mutable objects. In this example: • The tuple itself is fixed • But the list inside it is mutable So: ✔ You can modify the list ❌ But you cannot reassign elements of the tuple 📌 Core Idea A tuple stores references, not the actual values. That means: • You can’t change what the tuple points to • But you can modify the object if it’s mutable 💡 The “immutability” of a tuple means that the references it holds cannot be changed after creation. You cannot change which object a specific index in the tuple points to, nor can you add or remove elements from the tuple. 📌 Key Point A tuple is immutable, but it can contain mutable objects. #Python #PythonProgramming #CodingTips #DataStructures #LearnPython
To view or add a comment, sign in
-
🚀 Just completed a small but useful Python project! I built a simple script that helps clean and organize cluttered files automatically. You know how messy folders get with random downloads, images, and documents? This project sorts them into proper folders in seconds. While working on this, I didn’t just learn Python — I understood how automation can save time in real life. Small projects like this build strong fundamentals and confidence. 📌 What I learned: -Working with file handling in Python -Using automation to solve daily problems -Writing cleaner and more structured code -This is just the beginning. Next step: building more advanced projects. Would love your feedback and suggestions! code and git hub repo:-https://lnkd.in/dhvuVQAA #Python #BeginnerProjects #Automation #CodingJourney #LearningByDoing
To view or add a comment, sign in
-
🚀 Day 31 of My Python Full-Stack Journey 🐍 Today I learned about Types of Functions in Python based on Parameters and Return Values. Functions help us organize code and avoid repetition. Based on parameters and return values, functions can be classified into different types. 🔹 Function without Parameters and without Return Value This type of function does not take any input and does not return any value. It simply performs a task. Python Copy code def greet(): print("Hello, welcome to Python!") greet() 🔹 Function with Parameters and without Return Value This function takes input values but does not return anything. Python Copy code def greet(name): print("Hello", name) greet("Balaji") 🔹 Function with Parameters and Return Value This type takes input and returns a result using the return keyword. Python Copy code def add(a, b): return a + b result = add(5, 3) print(result) 🔹 Function without Parameters but with Return Value Python Copy code def get_number(): return 10 num = get_number() print(num) 💡 Key Takeaway: Understanding these function types helps in writing clean, reusable, and structured Python programs. Learning step by step and improving every day on my Python Full-Stack Journey 🚀 #Python #FullStack #CodingJourney #100DaysOfCode #PythonFunctions #LearningInPublic
To view or add a comment, sign in
-
-
🚀#120DaysChallenge of Python Full Stack Journey Hello everyone, I’m Lakshmi Sravani 😊 #120DaysChallenge #46Day - OOP Concepts in Python Today I explored some important Python concepts: 📌 Difference between _ and __ (Access Modifiers) _variable → Protected (can be accessed, but intended for internal use) __variable → Private (name mangling used to avoid conflicts in classes) Example: __salary becomes _ClassName__salary internally 📌 Name Mangling in Python Helps prevent variable conflicts, especially in multiple classes with same variable names. 📌 Polymorphism & Operator Overloading Same operator behaves differently for different data types Example: + works for numbers, lists, and strings 💡Python makes OOP powerful and flexible with simple syntax! #Python #OOPS #Coding #LearningJourney #FullStack
To view or add a comment, sign in
-
Rules for declaring python veriables:- 1) Must start with letters (a-z, A-Z) or underscore _ 2)Must not start with numbers (1 to .... ) 3) Variables are case sensitive ( python and Python both are different) 4) We cannot use keywords as variables ( if, def, while ...) Variable declaration is main part of any program. First impression will be starting with it, so while declaring variables need to take care. #python #learn #fast #beginner #automation
To view or add a comment, sign in
-
Started exploring Python fundamentals and recently learned about variables and data types. A few quick takeaways: → Python is dynamically typed — no need to declare types explicitly → Variables are just references to objects in memory → Core data types are simple yet powerful: • int (numbers) • float (decimals) • str (text) • bool (True/False) • list, tuple, dict (collections) What stood out is how readable and beginner-friendly Python feels compared to other languages. Small concepts, but they form the foundation for everything ahead. On to the next step 🚀 #Python #Learning #Developers #Programming #TechJourney
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