𝐈 𝐰𝐫𝐨𝐭𝐞 𝐭𝐡𝐞 𝐬𝐚𝐦𝐞 𝐥𝐢𝐧𝐞 𝟕 𝐭𝐢𝐦𝐞𝐬 𝐛𝐞𝐟𝐨𝐫𝐞 𝐥𝐞𝐚𝐫𝐧𝐢𝐧𝐠 𝐭𝐡𝐢𝐬 😩 A function is just a named block of code you can run anytime. def = define. then call it by name. 𝑾𝒉𝒚 𝒖𝒔𝒆 𝒕𝒉𝒆𝒎? → Write once, use many times → Easier to fix bugs (one place) → Cleaner code that humans can read 𝑲𝒆𝒚 𝒇𝒆𝒂𝒕𝒖𝒓𝒆𝒔: → 𝑷𝒂𝒓𝒂𝒎𝒆𝒕𝒆𝒓𝒔: Values you pass into a function so it can work with different data each time. → 𝙍𝙚𝙩𝙪𝙧𝙣: The value a function sends back to you after it finishes its job. → 𝘿𝙚𝙛𝙖𝙪𝙡𝙩 𝙖𝙧𝙜𝙪𝙢𝙚𝙣𝙩𝙨:Fallback values that a function uses if you don't pass anything for that parameter. → 𝘿𝙤𝙘𝙨𝙩𝙧𝙞𝙣𝙜𝙨: A short note inside a function that explains what it does (for you and others reading the code). 𝙁𝙪𝙡𝙡 𝙘𝙤𝙙𝙚 + 𝙚𝙭𝙖𝙢𝙥𝙡𝙚𝙨: 🔗 Vist my Github :https://lnkd.in/drGxebiM 𝑶𝒗𝒆𝒓 𝒕𝒐 𝒚𝒐𝒖: 👇 Type "GUILTY" if you've ever written the same loop 4 times in one script.😅 #python #AiEngineer #coding
Python Functions: Write Once, Use Many Times
More Relevant Posts
-
Day 6 of my Python learning journey: Focusing on writing code that's not just functional, but also dependable. Highlights from today: - Warmed up by practicing iterators and generators. - Solved the "First Non-Repeating Character" problem using a clean two-pass frequency approach with O(n) complexity. - Merged two sorted arrays efficiently through the two-pointer technique (O(n + m))—avoiding any redundant sorting. - Developed a FastAPI endpoint for the above problem, complete with schema validation. Observations: Initially, I attempted a one-pass solution for the non-repeating character problem, but it ended up feeling convoluted. Switching to a two-pass strategy made the solution much more straightforward and maintainable. Current focus areas: - Maintaining input order integrity. - Performing input validation early on. - Keeping logic as simple as possible. - Thoroughly testing edge cases beforehand. Major takeaway: Define inputs/outputs upfront → validate data early → then prioritize optimization. Starting to grasp how even minor design decisions can significantly impact code quality. GitHub link: https://lnkd.in/gGPw8_js #Python #FastAPI #ProblemSolving #SoftwareEngineering #CleanCode #LearningInPublic #OOP #Testing
To view or add a comment, sign in
-
-
Day 9 of #100DaysOfCode – Mastering Lists in Python 🐍 Today’s focus was completely on one powerful concept: 👉 Lists – the backbone of data handling in Python Instead of jumping between topics, I went deep into list operations and logic building 💻🧠 ✨ What I practiced today (Programs 101–115): 🔹 Core list operations ✔️ Sum, product, count of elements ✔️ Finding largest & smallest (without built-ins) ✔️ Second largest & second smallest 🔹 Logical problem solving ✔️ Count even & odd numbers ✔️ Separate positive & negative values ✔️ Find indices of elements 🔹 Real-world list handling ✔️ Remove duplicates (without set) ✔️ Reverse list using loop ✔️ Copy list manually ✔️ Rotate list 💡 Key Learning: Lists are not just collections… They are the foundation for solving real-world problems Today helped me understand: 👉 How to think without built-in shortcuts 👉 How logic works behind the scenes 🔥 The more I practice, the more confident I feel in problem solving 🙏 Special thanks to Global Quest Technologies (GQT) for continuous support and guidance throughout this journey 💬 One step closer to becoming a better developer every day Global Quest Technologies ✨ #100DaysOfCode #Day9 #Python #PythonProgramming #CodingJourney #LearnPython #DataStructures #ListsInPython #ProblemSolving #DeveloperMindset #TechSkills #SoftwareDevelopment #Consistency #GlobalQuestTechnologies #GQT
To view or add a comment, sign in
-
Day 58 of my #100DaysOfCode challenge 🚀 Today I implemented a Python program to generate prime numbers within a given range. This is a practical extension of prime checking and useful in many DSA and real-world problems. What the program does: • Takes a range (start, end) as input • Checks each number in the range • Identifies whether it is prime or not • Returns a list of all prime numbers in that range Example Output: Prime numbers between 1 and 50: [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47] How the logic works: Start from max(2, start) For each number: • Assume it is prime • Check divisibility from 2 → √n If divisible → not prime If not divisible → add to result list 👉 Uses square root optimization for better performance Why this is important: – Builds on prime number fundamentals – Useful in: Competitive programming Number theory problems Range-based queries – Helps understand optimization using √n Time Complexity: O(n√n) Space Complexity: O(k) (number of primes) Key Takeaways: – Applying optimized prime checking – Working with ranges and loops – Improving efficiency using √n – Writing clean and scalable code #100DaysOfCode #Day58 #Python #Programming #DSA #Algorithms #PrimeNumbers #NumberTheory #CodingPractice #ProblemSolving #InterviewPrep #Optimization #DeveloperJourney #Consistency #BTech #CSE #AIandML #VITBhopal #TechJourney
To view or add a comment, sign in
-
-
Day 59 of my #100DaysOfCode challenge 🚀 Today I implemented a Python program to count the number of set bits (1s) in a binary number. This uses an efficient bit manipulation technique and is very important in DSA & low-level optimization. What the program does: • Takes an integer n as input • Converts it conceptually to binary • Counts the number of set bits (1s) • Uses an optimized approach instead of checking each bit Example Outputs: 29 (11101) → 4 set bits 7 (111) → 3 set bits 16 (10000) → 1 set bit How the logic works: Uses Brian Kernighan’s Algorithm: n = n & (n - 1) • This removes the rightmost set bit in each step • Repeat until n = 0 • Count how many times this operation runs Why this is important: – Much faster than checking every bit ⚡ – Used in: Bit manipulation problems Competitive programming Low-level optimizations – Common in coding interviews Time Complexity: O(number of set bits) Space Complexity: O(1) Key Takeaways: – Understanding bitwise operations – Efficient counting techniques – Writing optimized solutions – Learning real-world low-level logic #100DaysOfCode #Day59 #Python #Programming #DSA #Algorithms #BitManipulation #Binary #CodingPractice #ProblemSolving #InterviewPrep #Optimization #DeveloperJourney #Consistency #BTech #CSE #AIandML #VITBhopal #TechJourney
To view or add a comment, sign in
-
-
💻 Solved a great problem today: Count Increasing Subarrays 🚀 Given an array, the task was to count all strictly increasing subarrays of size ≥ 2. 🔍 Approach I used: Broke the array into continuous increasing segments For each segment of length k, calculated subarrays using the formula: 👉 k(k-1)/2 Summed all results to get the final answer ⚡ Time Complexity: O(n) 📦 Space Complexity: O(n) 💡 This problem helped me understand how breaking a problem into patterns can simplify complex logic. Here’s my Python solution 👇 class Solution: def countIncreasing(self, arr): list2 = [] list2.append(arr[0]) list3 = [] for i in range(1, len(arr)): if arr[i-1] < arr[i] and arr[i] > 2: list2.append(arr[i]) else: list3.append(list2) list2 = [] list2.append(arr[i]) list3.append(list2) ans = 0 for i in list3: if len(i) > 1: ans += (len(i) * (len(i) - 1)) // 2 return ans 🔥 Always learning, always improving. #python #dsa #coding #problemSolving #programming #developers #learning
To view or add a comment, sign in
-
-
🚀 Day 12 – Exception Handling in Python Today I learned how to handle errors without crashing the program. 🔹 What is an Exception? An exception is a runtime error that disrupts the normal flow of a program. 🔹 Why Exception Handling? ✔ Prevents program crashes ✔ Handles errors gracefully ✔ Improves program reliability 🔹 Basic Syntax: try: # risky code except: # handling code 🔹 Example: try: num = int(input("Enter number: ")) print(10 / num) except: print("Error occurred") 🔹 Handling Specific Errors: try: x = int(input()) print(10 / x) except ZeroDivisionError: print("Cannot divide by zero") except ValueError: print("Enter valid number") 🔹 try - except - else: try: x = int(input()) y = int(input()) print(x / y) except ZeroDivisionError: print("Error") else: print("Success") 🔹 finally Block: Used to execute important code (like closing files), whether error occurs or not. 🔹 Nested Exception Handling: Handling exceptions inside another try block. 💡 Key Learning: Good developers don’t avoid errors… they handle them smartly. Ajay Miryala 10000 Coders #Python #ExceptionHandling #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
✅ Day 90 of 100 Days LeetCode Challenge Problem: 🔹 #476 – Number Complement 🔗 https://lnkd.in/gzE6gM7d Learning Journey: 🔹 Today’s problem focused on finding the complement of a number by flipping its binary bits. 🔹 I first converted the integer to its binary representation using bin(num)[2:]. 🔹 Then, I created a helper function to flip each bit: • '0' → '1' • '1' → '0' 🔹 After generating the flipped binary string, I converted it back to an integer using int(..., 2). 🔹 Returned the final complemented value. Concepts Used: 🔹 Binary Representation 🔹 Bit Manipulation 🔹 String Traversal 🔹 Base Conversion Key Insight: 🔹 The complement operation is essentially a bitwise NOT, but only within the significant bits of the number (ignoring leading zeros). 🔹 Converting to binary simplifies the flipping logic for beginners. Complexity: 🔹 Time: O(log n) 🔹 Space: O(log n) #LeetCode #Algorithms #DataStructures #CodingInterview #100DaysOfCode #Python #ProblemSolving #LearningInPublic #TechCareers
To view or add a comment, sign in
-
-
🚀 DSA Journey – Day 2 | Conditional Logic, Ternary Operator & Pythonic Optimization Today’s DSA practice focused on improving conditional logic and writing cleaner Python code. 📌 Topics covered: Even / Odd number check Pass / Fail logic using marks Ternary operator any() for optimized conditions Basic list-based condition checking 🐍 Problem 1: Even or Odd Started with a normal if-else approach and then optimized it using a reusable function and ternary operator. def is_even(n): return n % 2 == 0 print("even" if is_even(8) else "odd") 💡 Key learning: The ternary operator helps write short and clean conditional expressions. Example format: value_if_true if condition else value_if_false 📌 Problem 2: Pass / Fail using marks I first solved it using brute-force loops and counters, then optimized it using Python’s built-in any() function. def is_pass(marks: list): return any(i >= 35 for i in marks) print("pass" if is_pass([77, 15, 17]) else "fail") ⚡ What I learned today Writing shorter and cleaner conditions Replacing loops with optimized built-in functions Better readability using ternary expressions Thinking in a more Pythonic way 🔗 GitHub Code: https://lnkd.in/g9-HTPUP Day by day, I’m focusing on improving both logic building and clean coding practices. #DSA #Python #CodingJourney #100DaysOfCode #ProblemSolving #GitHub #LearningInPublic
To view or add a comment, sign in
-
Day 26/100: Writing Cleaner, Faster, and Pythonic Code! Today was all about efficiency and elegance. I dived deep into Comprehensions—one of Python’s most powerful features for creating new sequences from existing ones. Key Technical Takeaways: List Comprehension: Reducing multi-line for loops into a single, readable line. [new_item for item in list if test] Dictionary Comprehension: Creating complex mappings and filtering data on the fly. Conditionals in Comprehensions: Mastering how to use if and if-else inside a single line of code. Project: NATO Alphabet Converter: Developed a tool that takes any word and converts it into its NATO phonetic code (Alpha, Bravo, Charlie...) using dictionary comprehension. My code is becoming significantly shorter, more readable, and much more efficient. It’s amazing how a simple shift in syntax can make such a big difference in software quality! Check out my NATO Alphabet project here: https://lnkd.in/gZ2bdXua #Python #CleanCode #100DaysOfCode #Pythonic #SoftwareDevelopment #CodingEfficiency #VSCode
To view or add a comment, sign in
-
-
In my previous post, i talked about breaking code with one small change. This time? It gets worse. You write the code. 1 error. You fix the error. 12 new errors. And your screen is basically on fire. Every programmer has been here. Every single one. Here is the truth about errors in coding: Errors are not failure. They are feedback. Python does not hate you. It is telling you exactly what is wrong. Fixing one error exposing others means you are making progress. The code was always broken. Now you can finally see it. How to handle cascading errors like a professional: Fix from the top. The first error often causes all the others. Read the full error message. The answer is always in there. Do not fix everything at once. One error at a time. Take a break. Fresh eyes fix bugs faster than tired ones. Note: Debugging is not the obstacle. It is the job. #Python #Debugging #DataScience #LearnToCode #BeginnerCoder #Coding #StudentLife
To view or add a comment, sign in
-
Explore related topics
- Writing Functions That Are Easy To Read
- Key Skills for Writing Clean Code
- GitHub Code Review Workflow Best Practices
- Simple Ways To Improve Code Quality
- Ways to Improve Coding Logic for Free
- Coding Best Practices to Reduce Developer Mistakes
- How to Improve Your Code Review Process
- How to Write Clean, Error-Free Code
- Keeping Code DRY: Don't Repeat Yourself
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