Python 3 Program to Add Two Numbers Using Function in Terminal Tutorial For Complete Beginners
110 views
Jun 1, 2025
Get the full source code of application here:
View Video Transcript
0:00
uh hello guys welcome to this video so
0:02
in this video I will show you how to add
0:04
two numbers using a function inside
0:07
Python as uh other programming languages
0:11
you can even declare functions inside
0:12
Python functions makes the job way more
0:15
easier because you don't need to write
0:17
the entire code
0:19
uh in the one go you can declare
0:21
functions for that so now inside this
0:24
Python script you actually declare a
0:28
function so we declare the function
0:30
using this keyword here
0:33
def so here you will declare the name of
0:36
the function so in this case we are
0:38
declaring add and then you put this
0:42
parenthesis right here this is actually
0:44
your name of the function add and then
0:47
here you specify arguments that you will
0:50
be receiving in this function so a comma
0:52
b and then put a colon symbol so this is
0:56
representation of a function defaf
0:58
keyword the name of the function and a
1:01
comma b the arguments which will be
1:02
received in this function and colon and
1:05
then we specify we can directly add
1:08
these two numbers and return the result
1:10
you can directly write write this so
1:12
this will add these two numbers and
1:14
return this result from this function
1:16
and now to call this function you
1:20
simply directly can print out the result
1:24
in the terminal add these two numbers
1:26
let's suppose 10 20 so now the result
1:30
will come out 10 + 20 comes out to be 30
1:34
so if I execute this Python script you
1:36
will see it will print out 30 so this is
1:40
your result so in this easy
1:43
way you can actually add two numbers
1:46
using a function and now we can do this
1:49
little bit differently as well so inside
1:51
this
1:52
function we can store it in a variable
1:55
as well and then return this variable
1:58
instead like this this also will print
2:02
out the same result you will see
2:05
30 and here also instead of printing
2:09
out we can simply get this
2:13
value and then print out so this will
2:16
also return the same result so these are
2:19
two different approaches of doing the
2:21
same thing so you can see that so this
2:23
is actually the program very simple
2:28
program it's for complete beginners so
2:31
if you're complete beginner wanted to
2:33
know so in this way how we do this so if
2:36
I change the argument let's suppose I
2:37
say 10 and here I
2:43
say 20
2:49
20 comma 100 so this will
2:57
be 110 so in this way this can be minus
3:02
this can be multiplication divide any
3:05
sort of operator you can do so
3:07
essentially this is the way and also
3:10
check out my website freemediattools.com
3:13
uh which contains uh thousands of tools
#Calculators & Reference Tools
#Scripting Languages
#Software