PYTHON JOURNEY - Day 45 / 50..!! TOPIC – Function Arguments (Default & Keyword) Today I dived deeper into Functions by learning how to make them more flexible using Default and Keyword arguments. This allows me to handle different scenarios without writing multiple functions! 1. Default Arguments You can assign a "default" value to a parameter. If the user doesn't provide a value, Python uses the default one. Python def greet(name, message="Welcome to the team!"): print(f"Hi {name}, {message}") greet("Srikanth") # Uses default message greet("Srikanth", "Let's build something cool!") # Overwrites default 2. Keyword Arguments When calling a function, you can specify the parameter names. This means the order of arguments doesn't matter anymore! Python def describe_pet(pet_name, animal_type): print(f"I have a {animal_type} named {pet_name}.") # Order doesn't matter if you use keywords describe_pet(animal_type="Dog", pet_name="Buddy") 3. Combining Both You can have a mix of required and optional parameters to create highly professional and reusable code. Why Use Advanced Arguments? Flexibility: Your functions can handle various inputs without crashing. Readability: Keyword arguments make it obvious what each value represents (e.g., price=500 is clearer than just 500). Scalability: Allows you to add new features to a function without breaking the existing code that calls it. Mini Task Write a program that: Defines a function make_bill(item, price, tax=0.05). The function should calculate the total price (price + price * tax). Call it once with just item and price. Call it a second time and provide a custom tax value (e.g., 0.10) using a keyword argument. #Python #PythonLearning #50DaysOfPython #DailyCoding #LearnPython #CodingJourney #PythonForBeginners #LinkedInLearning #DeveloperCommunity
Srikanth parikibanda’s Post
More Relevant Posts
-
PYTHON JOURNEY - Day 47 / 50..!! TOPIC – List Comprehensions Today I explored one of Python’s most "elegant" features — List Comprehensions. It’s a shorthand way to create new lists based on existing ones, turning 4 lines of code into just 1! 1. The Traditional Way vs. Comprehension Normally, to create a list of squares, you’d need a for loop and .append(). With comprehension, it’s a single line! Python # Traditional Way nums = [1, 2, 3] squares = [] for x in nums: squares.append(x * x) # List Comprehension (The Pythonic Way) squares = [x * x for x in nums] print(squares) # Output: [1, 4, 9] 2. Adding a Condition (The if part) You can filter items while creating the list. Python prices = [10, 55, 80, 25, 100] # Only keep prices over 50 expensive = [p for p in prices if p > 50] print(expensive) # Output: [55, 80, 100] 3. String Manipulation It works perfectly for transforming text data too. Python names = ["srikanth", "python", "dev"] capitalized = [n.capitalize() for n in names] print(capitalized) # Output: ['Srikanth', 'Python', 'Dev'] Why Use List Comprehensions? Readability: Once you learn the syntax, it's much easier to read at a glance. Performance: They are generally faster than standard for-loops for creating lists. Professional: It is a hallmark of "Pythonic" code—showing you really know the language! Mini Task Write a program that: Creates a list of numbers from 1 to 10. Uses List Comprehension to create a new list containing only the even numbers. Prints the resulting list. #Python #PythonLearning #50DaysOfPython #DailyCoding #LearnPython #CodingJourney #PythonForBeginners #LinkedInLearning #DeveloperCommunity
To view or add a comment, sign in
-
-
🐍 Python in 60 Seconds — Day 8 Strings & String Operations Strings are how Python works with text. Anything inside quotes is a string. Example: text = "Python" You can use: • single quotes ' ' • double quotes " " Both work the same. ➕ Joining strings "Hello" + "World" → "HelloWorld" ⚠️ No spaces are added automatically. If you want a space, include it: "Hello " + "World" → "Hello World" 🔁 Repeating strings "Hi" * 3 → "HiHiHi" Yes, Python allows this 😄 📏 Length of a string len("Python") → 6 Spaces count too. 🔢 Strings are indexed word = "Python" word[0] → 'P' word[1] → 'y' word[-1] → 'n' Indexing starts at 0. Negative indices mean starting from the end, and they begin at -1. ⚠️ Beginner trap word[6] → Error (index out of range) Indexes must stay inside the string. 🔤 Escape characters (important ❗) An escape character is a special sequence that starts with a backslash \ It tells Python to treat the next character in a special way. They are characters inside the string, not commands. 📄 New line print("Hello\nWorld") Output: Hello World \n means “start a new line”. 📐 Tab (spacing) print("A\tB\tC") Output: A B C \t inserts horizontal spacing. 🔔 Common escape characters " → double quote ' → single quote \n → new line \t → tab ✅ Examples print("He said: \"Hello\"") print('It\'s Python') print("C:\\new\\text") 🧠 Key idea A string is not “one thing” — it is a sequence of characters, each with a position. 💡 Insight Numbers are for calculation. Strings are for expression. Python treats both as first-class citizens. 💫 Keep Experiementing! 🔮 Tomorrow String slicing & powerful text tricks #Python #LearnPython #Programming #Coding #TechCareers #DataScience #100DaysOfCode
To view or add a comment, sign in
-
-
Building a Wikipedia Search Engine in 10 Lines of Python! I’ve always been fascinated by how a few lines of clean code can bridge the gap between us and the world's information. I recently put together this mini-project: a Wikipedia Search Engine built entirely in Python. By leveraging the wikipedia library, I was able to create a script that takes a user keyword and instantly pulls a concise summary directly from the web. 🛠️ How it works: Library: Using the wikipedia wrapper to handle API requests seamlessly. Input: A simple user prompt to capture the search topic. Execution: The summary function fetches the first few sentences of the entry. Output: Clean, formatted results delivered straight to the terminal. It’s projects like these that remind me why Python is such a powerhouse for automation and data retrieval. It’s not just about the code; it’s about making information more accessible with minimal overhead. The Code: Python: import wikipedia topic = input("Enter keyword to search: ") print("="*30) print(f"Searching for: {topic}") print("="*30) res = wikipedia.summary(topic, sentences=3) print(res) print("="*30) What was the first "useful" script you ever wrote? Let’s talk about it in the comments! 👇 #Python #Coding #Automation #OpenSource #DataScience #SoftwareDevelopment #TechCommunity
To view or add a comment, sign in
-
🚀 From String Splits to Structured Data: A Quick Python Evolution Ever watched a simple Python script evolve? 😄 Started with extracting first names from a list: names = ["Charles Oladimeji", "Ken Collins"] fname = [] for i in names: fname.append(i.split()[0]) # Result: ['Charles', 'Ken'] Then flipped to last names: fname.append(i.split()[1]) # Result: ['Oladimeji', 'Collins'] Finally transformed it into clean, structured dictionaries: names = ["Charles Oladimeji", "Ken Collins", "John Smith"] fname = [] for i in names: parts = i.split() fname.append({"first": parts[0], "last": parts[1]}) # Result: [{'first': 'Charles', 'last': 'Oladimeji'}, ...] Why I love this progression: 1. Shows how small tweaks solve different problems 2. Demonstrates data structure thinking (list → list of dicts) 3. Real-world applicable for data cleaning/API responses 4. Sometimes the most satisfying code journeys start with a simple .split()! #DataEngineer #Python #Coding #DataTransformation #Programming
To view or add a comment, sign in
-
-
🔤 Master These Python String Methods & Level Up Your Code 🚀 Strings are everywhere in Python from user input to data processing. If you know these core string methods, your code instantly becomes cleaner, safer, and more professional. ✨ Must-know methods: • split() --> Break a sentence into words for text analysis • strip() --> Clean extra spaces from user input • join() --> Combine list items into a single string • replace() --> Update or sanitize text values • upper() --> Convert text to uppercase for consistency • lower() --> Normalize text for case-insensitive comparison • isalpha() --> Validate name fields (letters only) • isdigit() --> Check if input contains only numbers • startswith() --> Verify prefixes like country codes or URLs • endswith() --> Validate file extensions (.pdf, .jpg, etc.) • find() --> Locate a word or character inside a string 💡 Why they matter? ✔ Clean messy user input ✔ Validate data effortlessly ✔ Write readable, efficient logic ✔ Avoid common bugs in real projects If you’re learning Python , bookmark this 📌 Keep up the 𝐏𝐫𝐚𝐜𝐭𝐢𝐜𝐞 👍 𝐂𝐨𝐧𝐬𝐢𝐬𝐭𝐞𝐧𝐜𝐲 is the 𝐊𝐞𝐲 in 𝐏𝐫𝐨𝐠𝐫𝐚𝐦𝐦𝐢𝐧𝐠 💯 👇 Comment “Python” if you want a part-2 with real examples! #Python #PythonProgramming #Coding #LearnToCode #Developer #ProgrammingTips #CleanCode
To view or add a comment, sign in
-
-
PYTHON JOURNEY - Day 46 / 50..!! TOPIC – Python Modules Today I explored Modules — a way to organize code into separate files and use pre-written code from Python’s massive library. It’s like having a giant toolbox where you only pick the tools you need! 1. Importing Built-in Modules Python comes with many "batteries included" modules. To use them, we simply use the import keyword. Python import math print(math.sqrt(64)) # Output: 8.0 print(math.pi) # Output: 3.14159... 2. Using the random Module Perfect for games or selecting random data. Python import random options = ["Rock", "Paper", "Scissors"] print(random.choice(options)) # Picks a random item print(random.randint(1, 10)) # Random number between 1 and 10 3. Using alias and from You can give a module a nickname or import only a specific part of it to save memory. Python import datetime as dt from math import factorial print(dt.datetime.now()) print(factorial(5)) # Output: 120 Why Use Modules? Efficiency: Don't reinvent the wheel! Use proven code written by experts. Organization: Keep your project files clean by separating logic. Power: Modules allow Python to do everything from web scraping to Data Science and AI. Mini Task Write a program that: Imports the random module. Creates a list called players = ["Alice", "Bob", "Charlie", "David"]. Uses random.choice() to pick a random "Winner" from the list. Prints: "And the winner is... <name>! #Python #PythonLearning #50DaysOfPython #DailyCoding #LearnPython #CodingJourney #PythonForBeginners #LinkedInLearning #DeveloperCommunity
To view or add a comment, sign in
-
-
"Python String methods cheat sheet:-" ✓ Ever wondered how to manipulate strings like a pro in Python? ✓ Here’s a quick visual guide to the most useful string methods with real examples:- ✓ .lower() and .upper() ----- Convert text to lowercase or uppercase. ✓ .capitalize() and .title() ----- Make the first letter or every word’s first letter uppercase. ✓ .strip() ----- Remove unwanted whitespace from the edges. ✓ .startswith() and endswith() ----- Check if a string begins or ends with a specific substring ( returns "True/False" ). ✓ .split() ----- Break a string into a list based on a delimiter. ✓ .join() ----- Merge a list of strings into one string with a separator. ✓ .replace() ----- Swap substrings within a string. ✓ .find() and .index() ----- Locate the position of a substring ( ".index()" raises an error if not found ). ✓ .count() ----- Count occurrences of a substring. ✓ .snumeric() ----- Verify if a string contains only numeric characters ( returns "True/False" ). #Python #Programming #StringMethods #DataScience #PythonTips #CheatSheet
To view or add a comment, sign in
-
-
🐍 Master the Language: The Building Blocks of Python!📚 If you want to master Python, you have to speak its language. These 33 keywords are the reserved words that form the skeletal structure of every script, automation, and AI model you build. 💻🚀 🔍 Keyword Spotlight: The "in" Keyword The in keyword is one of Python's most versatile tools. It serves two main purposes: Membership Testing: It checks if a value exists within a sequence (like a list, string, or dictionary). Example: 'a' in 'apple' returns True. Iteration: It is used in for loops to iterate over an iterable object. Example: for item in list: 📂 Full Categorization: Logic & Truth: and, or, not, True, False, None Flow Control: if, elif, else, for, while, break, continue, pass Functions & Classes: def, return, lambda, class, yield Exception Handling: try, except, finally, raise, assert Structure & Scope: import, from, as, with, global, nonlocal, del, in, is 💡✨Pro-Tip for Beginners: You don't need to memorize these all at once! As you build projects, you’ll find yourself using if, for, and def 90% of the time. The others, like nonlocal or yield, are your "level-up" tools for more advanced logic. Which keyword gave you the most trouble when you first started learning? Let’s discuss in the comments! 👇 #PythonProgramming #CodingTips #DataScience #SoftwareEngineering #LearnToCode #PythonKeywords #TechEducation #Programming101
To view or add a comment, sign in
-
-
𝗗𝗮𝘆 𝟯𝟴: 𝗪𝗵𝘆 𝗬𝗼𝘂𝗿 𝗣𝘆𝘁𝗵𝗼𝗻 𝗖𝗼𝗱𝗲 𝗪𝗼𝗿𝗸𝘀… 𝗯𝘂𝘁 𝗙𝗲𝗲𝗹𝘀 𝗦𝗹𝗼𝘄. Have you ever written Python code that gives correct results, but takes way too long to run? Most of the time, the problem isn’t Python itself. It’s how we use it. Here are the most common performance mistakes I’ve learned to avoid 👇 𝟭. 𝗨𝘀𝗶𝗻𝗴 𝗹𝗼𝗼𝗽𝘀 𝘄𝗵𝗲𝗿𝗲 𝘃𝗲𝗰𝘁𝗼𝗿𝗶𝘇𝗮𝘁𝗶𝗼𝗻 𝗶𝘀 𝗽𝗼𝘀𝘀𝗶𝗯𝗹𝗲 Python loops are slow - especially over large datasets. ❌ Looping row by row ✅ Using Pandas / NumPy vectorized operations Vectorized code is not just shorter, it’s significantly faster. 𝟮. 𝗔𝗽𝗽𝗹𝘆𝗶𝗻𝗴 𝗳𝘂𝗻𝗰𝘁𝗶𝗼𝗻𝘀 𝗿𝗼𝘄-𝘄𝗶𝘀𝗲 𝗶𝗻 𝗣𝗮𝗻𝗱𝗮𝘀 Using .apply() feels convenient, but it often behaves like a hidden loop. Before using apply, ask: • Can this be done with built-in Pandas functions? • Can it be expressed as a vectorized operation? Most of the time - yes. 𝟯. 𝗟𝗼𝗮𝗱𝗶𝗻𝗴 𝗺𝗼𝗿𝗲 𝗱𝗮𝘁𝗮 𝘁𝗵𝗮𝗻 𝘆𝗼𝘂 𝗻𝗲𝗲𝗱 Reading entire tables or files when only a few columns are required wastes: • Memory • Time • Compute resources Always filter: • Columns • Rows • Date ranges as early as possible. 𝟰. 𝗥𝗲𝗰𝗮𝗹𝗰𝘂𝗹𝗮𝘁𝗶𝗻𝗴 𝘁𝗵𝗲 𝘀𝗮𝗺𝗲 𝗹𝗼𝗴𝗶𝗰 𝗿𝗲𝗽𝗲𝗮𝘁𝗲𝗱𝗹𝘆 If the same computation runs inside a loop or function multiple times: • Cache it • Store it once • Reuse the result Repeated computation silently kills performance. 𝟱. 𝗜𝗴𝗻𝗼𝗿𝗶𝗻𝗴 𝗱𝗮𝘁𝗮 𝘁𝘆𝗽𝗲𝘀 Wrong data types slow everything down. Examples: • Using an object instead of a category • Using float where int is enough • Storing dates as strings Correct dtypes = faster operations + lower memory usage. Python is fast enough for most data tasks; inefficient patterns are usually the real bottleneck. Writing efficient code matters as much as writing correct code. 𝗪𝗵𝗮𝘁 𝗣𝘆𝘁𝗵𝗼𝗻 𝗽𝗲𝗿𝗳𝗼𝗿𝗺𝗮𝗻𝗰𝗲 𝗶𝘀𝘀𝘂𝗲 𝘀𝘂𝗿𝗽𝗿𝗶𝘀𝗲𝗱 𝘆𝗼𝘂 𝘁𝗵𝗲 𝗺𝗼𝘀𝘁 𝘄𝗵𝗲𝗻 𝘆𝗼𝘂 𝗱𝗶𝘀𝗰𝗼𝘃𝗲𝗿𝗲𝗱 𝗶𝘁? 𝗟𝗲𝘁’𝘀 𝘀𝗵𝗮𝗿𝗲 𝗹𝗲𝗮𝗿𝗻𝗶𝗻𝗴𝘀 👇 #Python #DataScience #PerformanceOptimization #Pandas #NumPy #Analytics #Learning #CodingTips
To view or add a comment, sign in
-
📌 Why map(), filter() and zip() still matter in Python As I’ve been improving my Python fundamentals, I realized that some built-in functions like map(), filter(), and **zip() are often underestimated—yet they’re incredibly powerful when used in the right situations. 🔹 map() – transforming data efficiently map() is ideal when the goal is to apply the same operation to every element in a sequence. map(str, [1, 2, 3]) It keeps the intent clear: convert every element. This works especially well in data pipelines and functional-style code. Alternate approach (List Comprehension): [str(x) for x in [1, 2, 3]] Both are correct—choosing between them depends on readability and context. --- 🔹 filter() – selecting what matters When the goal is to keep only values that meet a condition, filter() communicates that intent very clearly. filter(lambda x: x > 0, [-1, 0, 1, 2]) It’s clean and memory-efficient due to lazy evaluation. Alternate approach (List Comprehension): [x for x in [-1, 0, 1, 2] if x > 0] List comprehensions are often more readable, but filter() fits nicely in functional pipelines. --- 🔹 zip() – working with related data zip() is one of the most practical built-ins for real-world problems. It allows you to iterate over multiple sequences together safely and cleanly. zip([1, 2], ['a', 'b']) This avoids index errors and improves code clarity—much better than manual indexing. --- 🚀 My key takeaway Python doesn’t force a single “right way.” Strong developers understand multiple approaches and choose the one that best fits the problem. Use list comprehensions for clarity Use map() and filter() for functional workflows Use zip() whenever dealing with parallel data Learning Python isn’t about avoiding tools—it’s about knowing when and why to use them. #Python #LearningPython #DeveloperJourney #Programming #CleanCode
To view or add a comment, sign in
More from this author
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