Sunday, October 19, 2008

Why Do Ice Skates Hurt The Arch Of My Foot

10) The functions PART 1

Functions are blocks of code repeated. Let's see how you define a function:

 
# / usr / bin / python

final test ( ) : # def initialize and are used with:
print "hello world " # code from the function

test () # function call


What's up? with final test (): you create a function is defined by final you give a name test () and using the : in the name of the function using the brackets () because they contain (if you need) the parameters, the code that comes after print "hello world" is unique code of the function means that if the function is invoked test () that code will not run.

Let's see how to use two or more functions together
 
# / usr / bin / python

final test () : # define a function:
print "hello world " # codice contenuto nella funzione

def linea () : #definisce una funzione
print #linea vuota

def due () : #definisce una funzione
linea () #chiamata alla funzione linea()
prova () #chiamata alla funzione prova()
linea () #chiamata alla funzione linea()

due () #chiamata alla funzione


Output:
  
bash-3.1 $ python prova.py

hello world

bash-3.1 $


What's happening? re-reading the code we can find that we call the function * only * two () But she draws the first line () where your code will print a blank line, then test () , which prints hello to video world, then again line () and we will have a blank line.

* * TO REMEMBER:
function calls must have the ().
USE identity

0 comments:

Post a Comment