𝘿𝙖𝙮 8/50𝘿𝙖𝙮𝙨𝘾𝙝𝙖𝙡𝙡𝙚𝙣𝙜𝙚 𝙁𝙪𝙣𝙘𝙩𝙞𝙤𝙣𝙨 𝙄𝙣 𝙋𝙮𝙩𝙝𝙤𝙣: A function is a block of code that performs a specific task. 👉 We can use functions as: ✅ reduce code repetition ✅ make code clean ✅ reuse code again and again 👉𝙎𝙮𝙣𝙩𝙖𝙭: def function_name(): #code : def greet(): print("Hello, Welcome to Python!") 𝙏𝙮𝙥𝙚𝙨 𝙤𝙛 𝙁𝙪𝙣𝗰𝙩𝙞𝙤𝙣𝙨 𝙞𝙣 𝙋𝙮𝙩𝙝𝙤𝙣: 🎯 𝘉𝘶𝘭𝘪𝘵 𝘐𝘯 𝘍𝘶𝘯𝘤𝘵𝘪𝘰𝘯𝘴: These are functions that are already provided by Python. 𝐂𝐨𝐝𝐞: print("Hello") len("Python") type(10) 🎯 𝘜𝘴𝘦𝘳-𝘥𝘦𝘧𝘪𝘯𝘦𝘥 𝘍𝘶𝘯𝘤𝘵𝘪𝘰𝘯𝘴: These are functions created by the user. 𝐂𝐨𝐝𝐞: def greet(): print("Hello") greet() 🎯 𝘍𝘶𝘯𝘤𝘵𝘪𝘰𝘯𝘴 𝘞𝘪𝘵𝘩𝘖𝘶𝘵 𝘗𝘢𝘳𝘢𝘮𝘦𝘵𝘦𝘳𝘴: A function that does not take any input. 𝐂𝐨𝐝𝐞: greet() 𝐨𝐮𝐭𝐩𝐮𝐭: Hello, Welcome to Python! 🎯 𝘍𝘶𝘯𝘤𝘵𝘪𝘰𝘯 𝘸𝘪𝘵𝘩 𝘗𝘢𝘳𝘢𝘮𝘦𝘵𝘦𝘳: A function that takes input values. 𝐂𝐨𝐝𝐞: def greet(name): print("Hello", name) greet("Durga") greet("Python") 𝐨𝐮𝐭𝐩𝐮𝐭: Hello Durga Hello Python 🎯 𝘍𝘶𝘯𝘤𝘵𝘪𝘰𝘯 𝘞𝘪𝘵𝘩 𝘙𝘦𝘵𝘶𝘳𝘯 𝘝𝘢𝘭𝘶𝘦: A function that returns a value. 𝐂𝐨𝐝𝐞: def add(a, b): return a + b result = add(10, 20) print("Sum =", result) 𝐨𝐮𝐭𝐩𝐮𝐭: Sum = 30 🎯 𝘍𝘶𝘯𝘤𝘵𝘪𝘰𝘯 𝘞𝘪𝘵𝘩𝘰𝘶𝘵 𝘙𝘦𝘵𝘶𝘳𝘯 𝘝𝘢𝘭𝘶𝘦: A function that does not return anything. 𝐂𝐨𝐝𝐞: def show(): print("Python") show() #coding #pythonbasics #50dayschallenge #motivation #bvcec #ece
Python Functions: Blocks of Code for Reusability
More Relevant Posts
-
Day 27 of My Python Full-Stack Journey 🐍 Today's challenge: Reverse the words in a sentence — without using .reverse() or .join() Sounds simple? It made me think differently about strings and loops. Here's the logic I built from scratch: python def reverse_words(sentence): words = [] word = "" for char in sentence: if char == " ": if word: words.append(word) word = "" else: word += char if word: words.append(word) # Rebuild sentence manually result = "" for i in range(len(words) - 1, -1, -1): result += words[i] if i != 0: result += " " return result print(reverse_words("Hello World from Python")) # Output: Python from World Hello Key takeaways from today: → Manual string parsing builds real intuition → Constraints force creativity — no shortcuts = deeper understanding → Every loop you write by hand teaches you what built-ins do under the hood 27 days in. Still going strong. 💪 What would YOU add to make this more efficient? #Python #100DaysOfCode #FullStack #PythonProgramming #CodingJourney #LearningInPublic #Day27
To view or add a comment, sign in
-
-
⚡ Just released FastIter, parallel iterators for Python 3.14+ For years, Python's Global Interpreter Lock (GIL) prevented threads from running Python code truly in parallel. Python 3.14 changes that. FastIter takes advantage of free-threaded mode to split work across CPU cores automatically, with 2 to 5.6x measured speedups on CPU-bound workloads. And it is written entirely in Python, no C extensions, no compiled code. Simple API, real parallelism, pure Python. If you work with large datasets, give it a try: pip install fastiter GitHub: https://lnkd.in/eKtJVsfH Feedback and contributions welcome 🙌 #Python #OpenSource #Performance #Parallelism #Python314
To view or add a comment, sign in
-
🐍 Day 11 of my Python Full-Stack Journey — Tuples! Today I explored one of Python's most underrated data structures: Tuples 📦 At first glance, they look just like lists — but the key difference? They're immutable. Once created, you can't change them. Here's what I learned: ✅ Creating a tuple → my_tuple = (1, 2, 3) or even just 1, 2, 3 ✅ Accessing elements → Same indexing as lists: my_tuple[0] ✅ Tuple unpacking → a, b, c = (10, 20, 30) — super clean! ✅ Single element tuple → Don't forget the trailing comma: (5,) not (5) ✅ Tuples as dictionary keys → Unlike lists, tuples are hashable! Why use tuples over lists? → Faster performance → Protects data from accidental modification → Great for returning multiple values from a function python def get_user(): return ("Alice", 25, "Developer") name, age, role = get_user() Simple, clean, and Pythonic. 💡 Still going strong on this journey — Day 12 coming tomorrow! 🚀 #Python #FullStackDevelopment #100DaysOfCode #PythonLearning #CodingJourney #Day11 #Tuples #LearnToCode
To view or add a comment, sign in
-
-
Day 32 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to implement a custom version of the isdigit() function. Instead of using Python’s built-in method, I created my own function to check whether a string contains only numeric digits. What the program does: • Takes a string as input • Checks each character in the string • Verifies whether it lies between '0' and '9' • Returns True if all characters are digits • Returns False otherwise How the logic works: 1)The function first checks if the string is empty 2)If it is empty, it returns False 3)The program iterates through each character in the string 4)It checks whether the character falls within the range '0' to '9' 5)If any character fails this condition, the function returns False 6)If all characters satisfy the condition, the function returns True Example: Input: "123" Output: True Input: "123a" Output: False Input: "-1" Output: False Input: "0" Output: True Why this is useful: – Helps understand how built-in functions work internally – Uses ASCII character comparison – Strengthens string validation logic Key learnings from Day 32: – Implementing built-in functionality manually – Understanding ASCII-based comparisons – Writing validation logic for strings – Strengthening Python fundamentals #100DaysOfCode #Day32 #Python #PythonProgramming #StringValidation #Algorithms #ProblemSolving #CodingPractice #LearnByDoing #ComputerScience #ProgrammingJourney #DeveloperGrowth #BTech #CSE #AIandML #VITBhopal #TechJourney
To view or add a comment, sign in
-
-
Over the last few days I've been building a small data analysis toolkit in Python. The idea is simple: Instead of solving the same data cleaning problems again and again across different projects, I want to create a small reusable set of functions. So far I've implemented a function for cleaning and normalizing column names in Pandas DataFrames: lowercase, removing whitespace, replacing spaces with underscores, etc. Right now I'm working on the next part: handling duplicates. The goal is to build a function that can: - detect duplicates - report them - automatically clean them depending on the chosen action Besides writing the function itself, I'm also focusing on: - writing clear docstrings - input validation - and adding tests It's a small step, but building things from scratch is one of the best ways I've found to really understand how tools work under the hood. More updates soon as the toolkit grows. #python #pandas #dataanalysis #machinelearning #learninginpublic
To view or add a comment, sign in
-
-
🐍 Python Concept I Use Often: Dictionary vs Defaultdict One small choice in Python can make your code cleaner, faster, and less error-prone. Problem Counting occurrences in a list using a normal dictionary usually looks like this: counts = {} for item in data: if item in counts: counts[item] += 1 else: counts[item] = 1 It works—but it’s verbose and easy to mess up. Better Approach Using defaultdict from collections: from collections import defaultdict counts = defaultdict(int) for item in data: counts[item] += 1 Why this matters ✔ Removes conditional checks ✔ Improves readability ✔ Reduces chances of KeyError ✔ Scales well in data processing pipelines Curious—what’s your go-to Python feature that instantly improves code quality? #Python #PythonDeveloper #CleanCode #BackendDevelopment #DataEngineering #ProgrammingTips #SoftwareEngineering
To view or add a comment, sign in
-
Day 2 of my Python journey🐍 Today I moved from basic syntax to handling user interaction and manipulating data. I applied these new concepts by writing a basic terminal-based calculator script. 🖥️ Here is a straightforward breakdown of the Day 2 concepts from the CodeWithHarry playlist: ⌨️ User Input: Learned to use the built-in input() function to capture data directly from the terminal console. 🔄 Typecasting: Coming from a JavaScript background where types are often coerced automatically, Python is stricter. I learned that inputs are received as strings by default and must be explicitly converted using functions like int() or float() before performing calculations. ✂️ String Slicing & Methods: Explored how Python handles text data, specifically using bracket syntax [start:end] for slicing, which is a clean and efficient way to extract substrings. Progress is steady. 📈 For those working across different languages, do you prefer stricter typing (like Python) or looser typing (like standard JavaScript) for daily tasks? 👇 #Python #LearningInPublic #SoftwareEngineering #FrontendDev #CodeWithHarry
To view or add a comment, sign in
-
-
Why does a += 10 give an error, but a = 2 then a += 10 works perfectly? 🤔 I made this mistake today and learned something crucial about Python's compound assignment operators. The wrong way: a += 10 # ERROR: name 'a' is not defined ❌ The right way: a = 2 # Initialize first a += 10 # Now it works! ✅ # Result: a = 12 Here's why: Compound operators like +=, -=, *=, /= are shortcuts that perform operations AND assignment together. When you write a += 10, Python actually executes a = a + 10 To add 10 to a, Python first needs to READ the current value of a. If a doesn't exist yet, there's nothing to read — hence the error! Key takeaway: Always initialize your variable before using compound operators. It's not just syntax — it's logic. Have you encountered this error before? What was your "aha!" moment with Python operators? 💡 #Python #CompoundOperators #AssignmentOperators #PythonBasics #CodingMistakes #LearnPython #ProgrammingFundamentals
To view or add a comment, sign in
-
-
🐍 Struggling to remember Python string methods? I've got you covered! I just created a FREE, beautifully designed PDF guide that breaks down 30+ essential string methods in the simplest way possible. 🎯 What's Inside: 📝 Case Conversion → upper(), lower(), title(), capitalize() 🔍 Searching Methods → find(), count(), startswith(), endswith() ✂️ Splitting & Joining → split(), join(), splitlines() 🧹 Cleaning Methods → strip(), lstrip(), rstrip() 🔄 Replacement → replace() with examples ✅ Validation → isalpha(), isdigit(), isalnum() 📏 Alignment → center(), ljust(), rjust(), zfill() Each method includes: • Simple, jargon-free explanations • Real code examples • Expected outputs • Practical use cases 💡 This guide is designed for absolute beginners but useful for anyone who needs a quick reference! 📥 Download it Feel free to share with anyone who's learning Python. What's your favorite Python string method? Drop it in the comments! 👇 #Python #LearnPython #ProgrammingTips #CodingLife #100DaysOfCode #PythonDevelopment #SoftwareEngineering #TechCommunity #FreeLearningResources.
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