Python Functions | Just enough Python

Опубликовано: 26 Март 2026
на канале: Ajay Tech
30
0

What is a user defined function

Let’s take a simple task – Calculate the interest on the balance in your bank account since the beginning of the year. In order to do that, you first need 3 things

account balance
interest rate
days since Jan 1st of the current year

def calculate_interest(balance,interest,days) :

interest_amount = balance * ( interest / 100 ) * ( days/365 )

return interest_amount

To call the function, all you have to do is to just follow the signature of the function.

interest_amount = calculate_interest(1200,10,100)
print ( interest_amount )

Think of functions as essentially outsourcing the processing to a different place. In a large project, each developer works on developing his/her own piece of logic. Eventually, all of them need to be linked together. Functions provide the most fundamental way in which logic can be clealy separated. Ofcourse, there are other things like modules, libraries etc that do the same at a much higher level, but that is a topic for another day.
https://ajaytech.co/python-user-defin...
https://ajaytech.co