🚀 TODAY I LEARNED : RETURN STATEMENTS & RETURN TYPES A return statement is used to send a value back from a function. It decides what the function outputs when it is called. ✅ Why is return important? Gives the final output of a function Allows us to store and reuse results Helps in calculations, data processing, and logic building 🔍 Return vs Print print() → displays the value (for the user) return → sends the value back (for the program) 👉 A real program should use return, not print. 📌 Types of Return Values: Returning a single value Returning multiple values (Python supports this!) Returning expressions Returning booleans Returning None (default when no return) 🎯 Simple Example: A function can return two values at once: def calc(a, b): return a+b, a*b 💡 Key Takeaway A function becomes powerful only when it returns something that your program can use later. #greatcoder #Python #PythonBasics #Programming #CodingJourney #LearnPython #Functions #LearningInPublic #TechLearning #SoftwareDevelopment #CareerGrowth #LinkedInTech GREATCODER TRAININGS LLP
Return Statements & Types in Python Programming
More Relevant Posts
-
🗓 Day 41 / 100 – #100DaysOfLeetCode 📌 Problem 2110: Number of Smooth Descent Periods of a Stock Today’s problem focused on identifying and counting smooth descent periods in a stock’s price history. A smooth descent period is a contiguous segment where each day’s price decreases by exactly 1 compared to the previous day. Even a single day counts as a valid period. 🧠 My Approach: Observed that the array can be broken into maximal descending segments where prices[i] = prices[i-1] - 1. Traversed the array while maintaining the current length of a smooth descent sequence. Whenever the smooth descent condition breaks, reset the length to 1. For each position, added the current length to the answer. This works because a descent segment of length k contributes: 1+2+3+⋯+k smooth descent periods in total. 💡 Key Learning: This problem reinforced a powerful counting technique: ✔ Break the array into valid segments ✔ Count subarrays using incremental accumulation ✔ Avoid nested loops by leveraging mathematical patterns It’s a great example of turning what looks like a subarray-counting problem into a simple single-pass solution. Another solid daily problem completed 🚀 #100DaysOfLeetCode #LeetCodeChallenge #Python #ProblemSolving #SlidingWindow #TwoPointers #Arrays #Algorithms #DSA #CompetitiveProgramming #SoftwareEngineering #CodingJourney #DeveloperJourney #LearningInPublic #TechStudent #CareerGrowth #Programming #KeepLearning
To view or add a comment, sign in
-
-
🗓 Day 36 / 100 – #100DaysOfLeetCode 📌 Problem 3583: Count Special Triplets Today’s problem involved identifying special triplets (i, j, k) such that: Updated the counters as I moved the pointer from left to right. This approach is O(n) and handles large constraints smoothly. 🧠 My Approach: A direct triple-nested loop would be far too slow for large inputs. Instead, I used two frequency counters: le → counts occurrences to the left of index j ri → counts occurrences to the right of index j For each element nums[j], I checked whether 2 × nums[j] exists on both sides: le[2 * nums[j]] counts possible i ri[2 * nums[j]] counts possible k The number of valid triplets contributed by this middle element is: 💡 Key Learning: This problem reinforced the power of: ✔ Prefix and suffix frequency tracking ✔ Avoiding brute force by reframing the relationship between indices ✔ Converting a relational condition into a multiplicative count The beauty of this challenge lies in translating a seemingly complex index-based condition into a clean counting formula. Another great day of sharpening pattern recognition and counting strategies 🚀 #100DaysOfLeetCode #LeetCodeChallenge #Python #ProblemSolving #FrequencyCounting #HashMaps #PrefixSuffix #Algorithms #DSA #CompetitiveProgramming #SoftwareEngineering #CodingJourney #LearningInPublic #DeveloperJourney #TechStudent #CareerGrowth #LogicBuilding #Programming #KeepLearning
To view or add a comment, sign in
-
-
💡 LeetCode Learning Journey: Contains Duplicate Problem Recently, I worked on the “Contains Duplicate” problem on LeetCode. Initially, I approached it with the classic nested loop method, which checks every element against all others. While this solution works logically, I realized it fails to pass large test cases due to O(n²) time complexity. After researching, I discovered a much cleaner and highly optimized solution using Python’s set(), which ensures O(n) time complexity by storing already seen elements and checking for duplicates instantly: return len(nums) != len(set(nums)) I was truly impressed by the simplicity and efficiency of this approach! 🚀 ✅ Key Learning Points: Using set in Python for uniqueness and fast membership checks How time complexity impacts large inputs in competitive programming Importance of optimizing code beyond just correctness I’ve included a screenshot of my longer initial solution as well as the optimized one-line solution for comparison. It’s amazing how a single line can outperform nested loops for large datasets! #Python #LeetCode #ProblemSolving #DataStructures #CodingJourney #OOP #Set #Programming #Optimization
To view or add a comment, sign in
-
-
🗓 Day 40 / 100 – #100DaysOfLeetCode 📌 Problem 3775: Reverse Words With Same Vowel Count Today’s problem was a nice mix of string manipulation and character counting. The task was to analyze a sentence word by word and selectively reverse words based on a vowel-count condition. 🧠 My Approach: Split the input string into individual words using spaces. Counted the number of vowels (a, e, i, o, u) in the first word — this becomes the reference count. For each subsequent word: Counted its vowels. If the count matched the first word’s vowel count, reversed the word. Otherwise, left it unchanged. Joined all words back together to form the final string. 💡 Key Learning: This problem reinforced: ✔ careful string parsing ✔ clean set-based vowel checking ✔ conditional transformations based on computed properties ✔ attention to problem statements — especially “based on the first word” rules It’s a good reminder that many medium problems are about implementing logic precisely, not complexity. Another clean string-processing problem completed 🚀 #100DaysOfLeetCode #LeetCodeChallenge #Python #ProblemSolving #StringManipulation #VowelCounting #Algorithms #DSA #CompetitiveProgramming #SoftwareEngineering #CodingJourney #DeveloperJourney #LearningInPublic #TechStudent #CareerGrowth #Programming #KeepLearning
To view or add a comment, sign in
-
-
🚀 Learning Python by Building Real Projects Created an automated Monthly Expense Report using NumPy & OpenPyXL—from daily tracking to weekly summaries and key financial metrics, all exported to Excel. Hands-on projects truly accelerate learning 💡 GitHub:- https://lnkd.in/gayMx4q7 #PythonProgramming #BeginnerToPro #DataHandling #ExcelAutomation 🐍
To view or add a comment, sign in
-
-
🗓 Day 60 / 100 – #100DaysOfLeetCode 📌 Problem 1411: Number of Ways to Paint N × 3 Grid Today’s problem was a really good exercise in dynamic programming and pattern observation. The goal was to count the number of valid ways to paint an n × 3 grid using three colors, such that no two adjacent cells (horizontal or vertical) share the same color. 🧠 My Approach: Instead of tracking every possible coloring explicitly, I categorized each row into two patterns: 1️⃣ same – Rows where the 1st and 3rd cells have the same color (e.g., A B A) 2️⃣ diff – Rows where all three cells have different colors (e.g., A B C) For the first row: same = 6 diff = 6 Then for each subsequent row: A same pattern can be formed from: previous same rows in 3 ways previous diff rows in 2 ways A diff pattern can be formed from: previous same rows in 2 ways previous diff rows in 2 ways Using these transitions, I iterated row by row and applied modulo 10^9 + 7 to handle large values efficiently. 💡 Key Learning: This problem reinforced: ✔ breaking complex constraints into manageable states ✔ recognizing repeating patterns to optimize DP solutions ✔ reducing a large state space into just a few variables ✔ how mathematical transitions can drastically simplify implementation A perfect example of how thinking in patterns turns a hard-looking problem into a clean and elegant solution 🚀 #100DaysOfLeetCode #LeetCodeChallenge #Python #ProblemSolving #DynamicProgramming #DP #Combinatorics #Algorithms #DSA #CompetitiveProgramming #SoftwareEngineering #CodingJourney #DeveloperJourney #LearningInPublic #TechStudent #CareerGrowth #Programming #KeepLearning
To view or add a comment, sign in
-
-
🗓 Day 59 / 100 – #100DaysOfLeetCode 📌 Problem 961: N-Repeated Element in Size 2N Array Today’s problem focused on identifying a repeating pattern in an array with well-defined constraints. The task was to find the element that appears n times in an array of size 2n, where all other elements are unique. 🧠 My Approach: I used a set-based approach to track elements as I traversed the array: Iterated through each element in the array. Stored visited elements in a set. If an element was already present in the set, that meant it was the repeated element → returned it immediately. This works efficiently because the problem guarantees exactly one element is repeated n times. 💡 Why this works well: Sets provide O(1) average time complexity for lookup. The repeated element is guaranteed to appear early due to frequency, so we can exit early. Simple logic with clean and readable code. 💡 Key Learning: This problem reinforced: ✔ how problem constraints can simplify the solution ✔ effective use of hash-based data structures ✔ recognizing patterns instead of overcomplicating logic ✔ writing efficient solutions even for “easy” problems A great example of how understanding constraints leads to elegant solutions 🚀 #100DaysOfLeetCode #LeetCodeChallenge #Python #ProblemSolving #Arrays #HashSet #Simulation #Algorithms #DSA #CompetitiveProgramming #SoftwareEngineering #CodingJourney #DeveloperJourney #LearningInPublic #TechStudent #CareerGrowth #Programming #KeepLearning
To view or add a comment, sign in
-
-
🚀 Day 45 of #100DaysOfCode — Finding the Index of an Element in an Array Hey everyone! 👋 Today’s challenge focused on searching for an element in an array and returning its index. If the element doesn’t exist, we return -1 — simple but fundamental logic 💡 👨💻 What I practiced today: ✅ Implementing a linear search ✅ Iterating through arrays using loops ✅ Handling “not found” cases gracefully ✅ Writing clean and readable Python functions 📌 Today's Task: ✔ Create a function findIndex(arr, element) ✔ Return the index of the given element ✔ Return -1 if the element is not present 🧠 Example: Input: [1, 2, 3], 2 Output: 1 Input: ["a", "b", "c"], "c" Output: 2 Input: [5, 8, 10], 3 Output: -1 💡 Key Takeaway: A simple loop can solve many problems efficiently. Linear search is easy to understand and works well for small to medium datasets. #100DaysOfCode #Python #Arrays #Programming #ProblemSolving #LearningToCode #CodingJourney #Day45
To view or add a comment, sign in
-
-
🚀 Day 45 of #100DaysOfCode — Finding the Index of an Element in an Array Hey everyone! 👋 Today’s challenge focused on searching for an element in an array and returning its index. If the element doesn’t exist, we return -1 — simple but fundamental logic 💡 👨💻 What I practiced today: ✅ Implementing a linear search ✅ Iterating through arrays using loops ✅ Handling “not found” cases gracefully ✅ Writing clean and readable Python functions 📌 Today's Task: ✔ Create a function findIndex(arr, element) ✔ Return the index of the given element ✔ Return -1 if the element is not present 🧠 Example: Input: [1, 2, 3], 2 Output: 1 Input: ["a", "b", "c"], "c" Output: 2 Input: [5, 8, 10], 3 Output: -1 💡 Key Takeaway: A simple loop can solve many problems efficiently. Linear search is easy to understand and works well for small to medium datasets. #100DaysOfCode #Python #Arrays #Programming #ProblemSolving #LearningToCode #CodingJourney #Day45
To view or add a comment, sign in
-
-
🚀 Day 17 of #PythonLearningJourney Today’s learning was focused on Python functions and advanced argument handling, which helped me understand how flexible and powerful functions can be when written correctly. I explored different ways of passing arguments such as positional and keyword arguments, along with default parameters. I also practiced using *args to handle variable-length positional arguments and **kwargs to work with dynamic keyword arguments. This made function definitions far more adaptable to real-world scenarios. Along with this, I worked on returning values from functions, building utility functions like factorial calculation and palindrome checking, and understanding how unpacking works inside function parameters. I also explored concepts like swapping values, filtering data using conditions inside functions, and printing structured outputs. To strengthen logic-building, I implemented a Pascal’s Triangle generator and experimented with custom constraints while finding minimum values using function arguments. 🔹 What I Learned Today Difference between positional and keyword arguments How default parameters work in functions Using *args for multiple positional inputs Using **kwargs for flexible key-value inputs Returning values from functions effectively Writing reusable functions (factorial, palindrome check, utilities) Implementing logical patterns like Pascal’s Triangle Functions are truly the backbone of clean, reusable, and scalable Python code. Looking forward to diving deeper! 🚀 #PythonLearningJourney #CodingPractice #LearnPython #ProgrammingJourney #100DaysOfCode
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