Thread: def my_abs()?
View Single Post
Old Feb 25th, 2005, 5:40 PM   #2
Fred
Programmer
 
Fred's Avatar
 
Join Date: Feb 2005
Posts: 67
Rep Power: 4 Fred is on a distinguished road
The 'def' statement defines a so called function. You define it, and then you can use it with whichever numbers you want.
def my_abs(num): #num is a placeholder, so you can put in whichever 
    if num < 0:                           number you like
        num = -num
    return num

if my_abs(a) == my_abs(b):
This simply 'calls' the function. Meaning, that it is applied with the value of 'a', and then with the value of 'b' --> those were assigned to +-23.
my_abs(a) simply replaces every 'num' in the function with a 23, and then returns that value, so it can be compared to the absolute value of 'b', which is determined the same way.
I hope this helped a bit...
Fred is offline   Reply With Quote