🚀 Python Learning Series – Day 4 Aaj maine Functions in Python ke baare me seekha 👇 Functions ka use code ko reusable aur organized banane ke liye hota hai. Ek baar function likho, aur use multiple baar use karo. 🔹 Function kya hota hai? Ek block of code jo specific task perform karta hai 🔹 Kaise banate hain? "def" keyword ka use karke function define kiya jata hai 🔹 Parameters & Return Value - Parameters: input jo function ko diya jata hai - Return: output jo function wapas deta hai 💡 Simple Example: def add(a, b): return a + b result = add(5, 3) print(result) 👉 Output: 8 📌 Real Life Example: Jaise ek machine jo input leti hai aur output deti hai ⚙️ ✨ Aaj ka learning: Functions help in writing clean, reusable, and efficient code. #Python #Learning #CodingJourney #Functions #Programming #Beginners
Python Functions: Reusable Code Blocks
More Relevant Posts
-
🚀 Python Learning Series – Day 3 Aaj maine Loops (for & while) ke baare me seekha 👇 Programming me loops ka use ek hi kaam ko baar-baar repeat karne ke liye hota hai, bina code ko multiple baar likhe. 🔹 for loop Jab hume kisi sequence (list, range, string) par iterate karna ho tab use hota hai 🔹 while loop Jab tak condition true rahe, tab tak code repeat hota rehta hai 💡 Simple Example (for loop): for i in range(1, 6): print(i) 👉 Output: 1 se 5 tak numbers print honge 💡 Simple Example (while loop): i = 1 while i <= 5: print(i) i += 1 👉 Yeh bhi 1 se 5 tak numbers print karega 📌 Real Life Example: Jaise daily routine — jab tak kaam complete na ho, tab tak karte rehna 🔄 ✨ Aaj ka learning: Loops help in reducing code repetition and make programs efficient. #Python #Learning #CodingJourney #Loops #ForLoop #WhileLoop #Beginners
To view or add a comment, sign in
-
🚀 Python Learning Series – Day 6 Aaj maine List Comprehension in Python ke baare me seekha 👇 List comprehension ek short aur powerful tarika hai list banane ka, jisse hum kam code me same kaam kar sakte hain. 🔹 List Comprehension kya hota hai? Ek concise way hai list create karne ka using a single line of code 🔹 Basic Syntax: [expression for item in iterable] 💡 Example (Without List Comprehension): numbers = [] for i in range(1, 6): numbers.append(i*i) print(numbers) 💡 Same Example (With List Comprehension): numbers = [i*i for i in range(1, 6)] print(numbers) 👉 Output: [1, 4, 9, 16, 25] 📌 Real Life Example: Jaise ek shortcut method jo kaam ko fast aur easy bana deta hai ⚡ ✨ Aaj ka learning: List comprehension makes code cleaner, shorter, and more efficient. #Python #Learning #CodingJourney #ListComprehension #Programming #Beginners
To view or add a comment, sign in
-
🚀 Python Learning Series – Day 11 Aaj maine Error Handling (try-except) in Python ke baare me seekha 👇 Programming me kabhi-kabhi errors aa jate hain (jaise wrong input, file not found, etc.). In errors ko handle karne ke liye try-except ka use hota hai. 🔹 try block Isme wo code likhte hain jisme error aa sakta hai 🔹 except block Agar error aata hai to yeh block execute hota hai 🔹 Kyun use karte hain? Taaki program crash na ho aur smoothly chale 💡 Simple Example: try: num = int(input("Enter a number: ")) print(10 / num) except ZeroDivisionError: print("Cannot divide by zero!") except ValueError: print("Invalid input!") 👉 Yeh code different errors ko handle karta hai 📌 Real Life Example: Jaise kisi kaam me problem aaye to uska backup plan ready rakhna ⚠️ ✨ Aaj ka learning: Error handling helps in making programs safe and user-friendly. #Python #Learning #CodingJourney #ErrorHandling #TryExcept #Programming #Beginners
To view or add a comment, sign in
-
🚀 Python Learning Series – Day 9 Aaj maine Sets in Python ke baare me seekha 👇 Set ek data structure hai jisme unique elements store hote hain (duplicate values allow nahi hoti). 🔹 Set kya hota hai? Ek unordered collection jisme har element unique hota hai 🔹 Kaise banate hain? Curly braces "{}" ka use karke 🔹 Unique Values Agar duplicate values add karte ho, to set automatically unhe remove kar deta hai 🔹 Add / Remove elements - "add()" → element add karne ke liye - "remove()" → element delete karne ke liye 💡 Simple Example: numbers = {1, 2, 2, 3, 4} numbers.add(5) numbers.remove(2) print(numbers) 👉 Output: {1, 3, 4, 5} 📌 Real Life Example: Jaise ek group jahan har member unique hota hai — koi duplicate nahi 👥 ✨ Aaj ka learning: Sets help in storing unique data and removing duplicates easily. #Python #Learning #CodingJourney #Sets #Programming #Beginners
To view or add a comment, sign in
-
🚀 Python Learning Series – Day 8 Aaj maine Tuple in Python ke baare me seekha 👇 Tuple ek data structure hai jo list ki tarah hota hai, lekin yeh immutable hota hai (matlab isme changes nahi kar sakte). 🔹 Tuple kya hota hai? Ek ordered collection jisme multiple elements store hote hain 🔹 Kaise banate hain? Parentheses "()" ka use karke 🔹 Immutable kya hota hai? Ek baar tuple create ho gaya, uske baad usme koi change nahi kar sakte 🔹 List vs Tuple - List → change ho sakti hai (mutable) - Tuple → change nahi hota (immutable) 💡 Simple Example: numbers = (1, 2, 3, 4) print(numbers[0]) # Access element # numbers[1] = 10 ❌ Error (tuple immutable hota hai) 👉 Output: 1 📌 Real Life Example: Jaise Aadhaar number ya date of birth — ek baar set ho gaya to change nahi hota 📄 ✨ Aaj ka learning: Tuples are useful when data should remain constant. #Python #Learning #CodingJourney #Tuple #Programming #Beginners
To view or add a comment, sign in
-
🚀 Day 13 of Python Learning: Exception Handling in Python Today I learned how to handle errors in Python using exception handling. This helps programs run smoothly even when unexpected issues occur. 🔹 What is Exception Handling? Exception handling is used to catch errors and prevent the program from crashing. 🔸 Basic Example try: num = 10 / 0 except: print("Error occurred") 🔸 Handling Specific Error try: number = int("abc") except ValueError: print("Invalid input") 🔸 Using Finally Block try: print("Start") except: print("Error") finally: print("This always runs") 🔸 Using Else Block try: print(10 / 2) except: print("Error") else: print("No error found") 💡 Key Learning: Using try-except makes programs more reliable and user-friendly. 🧪 Practice Task: ✔ Handle divide by zero error ✔ Handle invalid number input ✔ Use finally block in one program ✔ Create a safe calculator using try-except 🎯 Interview Question: What is the purpose of finally block in Python? Answer: The finally block always executes whether an error occurs or not. It is commonly used for cleanup tasks like closing files or database connections. 📌 Day 13 completed — learning how professionals handle errors! #Python #Learning #CodingJourney #Day13 #Programming #SDET #100DaysOfCode Masai #masaiverse #dailylearning
To view or add a comment, sign in
-
🚀 Day 6 of Python Learning: Functions in Python Today I learned how to organize and reuse code using functions — a key concept for writing clean and efficient programs. 🔹 What is a Function? A function is a block of code that performs a specific task and can be reused whenever needed. 🔸 Creating a Function Example: def greet(): print("Hello, welcome to Python!") greet() 🔸 Function with Parameters Example: def greet(name): print("Hello", name) greet("Rohit") 🔸 Function with Return Value Example: def add(a, b): return a + b result = add(5, 3) print(result) 💡 Key Learning: Functions help reduce code repetition and make programs more structured and readable. 🧪 Practice Task: Create a function to check even or odd Create a function to add two numbers Create a function to find the square of a number 🎯 Interview Question: What is the difference between return and print in Python? Answer: "print displays output on the screen, while return sends the value back to the function caller." #Python #Learning #CodingJourney #Day6 #Programming #SDET Masai #dailylearning #masaiverse #SDET
To view or add a comment, sign in
-
-
Day 17 : of My Python Learning Journey Today I pushed the boundaries of Lambda Functions and List Comprehension to handle more complex logic in single lines ⚡ 🔹 What I learned and practiced: ✔️ Conditional Lambdas Writing Lambda functions that include if-else logic. Handling different return values based on input conditions without a full def block. ✔️ Nested List Comprehensions Using list comprehension within another list comprehension. 🔹 Hands-on Practice: ✔️ Created a lambda function to check if a number is positive, negative, or zero in one expression. ✔️ Used nested list comprehension to extract specific elements from a list of lists (matrices). Key takeaway: By combining List Comprehension with Lambda, we can transform and filter data structures simultaneously, keeping the code concise and highly efficient. Learning consistently and improving my coding skills step by step 💪 #Python #Lambda #codegnan #CodingJourney
To view or add a comment, sign in
-
-
Day 17 of my Python learning journey Today I tried another interesting problem using the Two Pointer technique. Problem: Valid Palindrome Given a string, check if it can become a palindrome after removing at most one character. Example: s = "abca" Output: True Because removing 'c' makes it "aba" which is a palindrome. What I understood: We need to check if the string is almost a palindrome, allowing one mistake. Better approach (Two Pointer): Start one pointer from left Start one pointer from right If characters match → move both pointers If mismatch → try skipping one character (either left or right) Code I wrote: def is_palindrome(s, left, right): while left < right: if s[left] != s[right]: return False left += 1 right -= 1 return True s = "abca" left = 0 right = len(s) - 1 while left < right: if s[left] != s[right]: if is_palindrome(s, left + 1, right) or is_palindrome(s, left, right - 1): print(True) else: print(False) break left += 1 right -= 1 else: print(True) Problems I faced while coding this: At first I tried removing every character and checking, which was inefficient. I was confused about which character to remove when mismatch happens. Writing a helper function for checking palindrome took some time to understand. What I finally understood: At the first mismatch, we only need to try two cases: skip left character skip right character If any one works, the string is valid. Time and Space Complexity: Time Complexity: O(n) Space Complexity: O(1) Question: What will be the output for: s = "abc" Today’s realization: Sometimes solving a problem is about allowing one controlled mistake. #Python #DSA #Coding #Programming #LearningInPublic #100DaysOfCode #PythonProgramming
To view or add a comment, sign in
-
-
Decision Making (if-else) Today I learned how Python makes decisions using conditions. This is one of the most important concepts in programming. 🔹 What is Decision Making? It allows a program to take actions based on conditions. 🔸 if Statement Used to execute code only if a condition is true. Example: age = 18 if age >= 18: print("You can vote") 🔸 if-else Statement Executes one block if condition is true, otherwise another block. Example: age = 16 if age >= 18: print("Eligible") else: print("Not eligible") 🔸 if-elif-else Statement Used when we have multiple conditions. Example: marks = 75 if marks >= 90: print("Grade A") elif marks >= 60: print("Grade B") else: print("Grade C") 💡 Key Learning: Indentation is very important in Python. It defines the structure of code. 🧪 Practice Task: Create a program that checks whether a number is even or odd. 🎯 Interview Question: What is the difference between if and elif? Answer: "if" checks a condition independently, while "elif" is used to check multiple conditions in sequence. #Python #Learning #CodingJourney #Day4 #Programming #SDET Masai #dailylearning #masaiverse
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