Functions in Python
Functions are one of the most powerful and essential concepts in programming. They allow us to break down complex problems into smaller…
Functions in Python
Functions are one of the most powerful and essential concepts in programming. They allow us to break down complex problems into smaller, reusable pieces of logic. In Python, functions make code more organized and efficient.
def welcome_user(name):
return f"Hello {name}, welcome to the Python world!"
print(welcome_user("Dhanush"))
print(welcome_user("Reader"))
What is a function
A function is a block of code that performs a specific task. Instead of writing the same code again and again, we can write it once inside a function and reuse it whenever needed. In simple words, a function is like a machine: you give it input, it processes it, and it gives output.
def greet(name):
return "Hello " + name
Syntax of a Function
In Python, we use the def keyword to create a function.
def function_name(parameters):
# code
return value
Here:
def is used to define a function
function_name is the name of the function
parameters are inputs
return gives output

Example of a Function
def greet(name):
return "Hello " + name
This function takes a name as input and returns a greeting message.
Calling a Function
After creating a function, we need to call it to use it.
print(greet("Dhanush"))
Output: Hello Jaan

Why Functions Are Powerful
Functions helped me:
Save time
Avoid mistakes
Write clean code
Real-Life Example
Think about a calculator. When you press a button for addition, it performs the same operation every time. Similarly, a function performs a fixed task whenever we call it.
Final Thought
Instead of writing code again and again, functions help us think smarter. That's when coding becomes easy.
메타데이터
- post_id
- 2e821e88aec2
- slug
- functions-in-python-2e821e88aec2
- url
- https://medium.com/@dhanushyadav290/functions-in-python-2e821e88aec2
- canonical_url
- https://medium.com/@dhanushyadav290/functions-in-python-2e821e88aec2
- author_url
- https://medium.com/@dhanushyadav290
- status
- ok
- fetched_at
- 2026-07-08 11:35:31