Srikanth parikibanda’s Post

PYTHON JOURNEY - Day 44 / 50..!! TOPIC – Functions (Basics) Today I explored Functions — the building blocks of reusable code. Instead of writing the same logic over and over, I can now wrap it in a function and call it whenever I need it! 1. Defining a Function We use the def keyword followed by the function name and parentheses. Python def greet(): print("Hello! Welcome to Day 44.") # Calling the function greet() 2. Functions with Parameters You can pass information into a function so it can perform dynamic tasks. Python def welcome_user(name): print(f"Hi {name}, keep up the great coding!") welcome_user("Srikanth") 3. The return Statement Functions can send data back to the main part of the program. Python def add_numbers(a, b): return a + b result = add_numbers(10, 20) print(f"The total is: {result}") Why Use Functions? Reusability: Write once, use everywhere! Organization: Breaks a large, messy program into small, manageable chunks. Testing: It’s much easier to test a small function than a 100-line script. Mini Task Write a program that: Defines a function called calculate_area that takes length and width as parameters. The function should return the area (length * width). Call the function with values 5 and 10 and print the result. #Python #PythonLearning #50DaysOfPython #DailyCoding #LearnPython #CodingJourney #PythonForBeginners #LinkedInLearning #DeveloperCommunity

  • diagram

To view or add a comment, sign in

Explore content categories