![]() |
|
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Nov 2006
Posts: 19
Rep Power: 0
![]() |
Defining a Function
Heh, I seem to be all over this forum, causing myself no end of confusion trying to find a language I can bear with. Given enough time I"ll find my niche, and only be in one forum; this is the goal anyway.
Furthermore, the same people keep answering my questions, so, as before, if you can keep your annoyance level to a minimum, I"ll get less abrasive eventually. ![]() Anyway, looking over, yes, another online tutorial, I need a little clarification. I've come to the section on declaring functions, and the given example sort of throws me. It is as follows: ( with the text from the tutorial ) The program seems a little repetitive. (Programmers hate to repeat things (That's what computers are for aren't they?)) Fortunately Python allows you to create functions to remove duplication. Here is the rewritten example: a = 23
b = -23
def my_abs(num):
if num < 0:
num = -num
return num
if my_abs(a) == my_abs(b):
print "The absolute values of", a,"and",b,"are equal"
else:
print "The absolute values of a and b are different"I understand what it's doing, but now the how of it. Is code with Python not sequential? What's causing the confusion is the def my_abs(num):
if num < 0:
num = -num
return numI see nothing declaring what (num) is. Does it get the value from the if my_abs(a) == my_abs(b): Because, it seems, following the code line by line, that the program wouldn't know what to do with the if num < 0:. |
|
|
|
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Compiling Maverik 6.2 (from C) | megamind5005 | C | 16 | May 3rd, 2006 5:41 PM |
| libraries | matko | C | 1 | Jan 22nd, 2006 2:12 PM |
| Php Postgresql Class | Pizentios | Show Off Your Open Source Projects | 15 | Jun 28th, 2005 9:55 AM |
| Jackpot game | zorin | Visual Basic | 3 | Jun 10th, 2005 1:19 PM |
| airport Log program using 3D linked List : problem reading from file | gemini_shooter | C++ | 0 | Mar 2nd, 2005 4:12 PM |