[Tutor] Functions output

Alan Gauld alan.gauld at btinternet.com
Sat Apr 18 00:39:26 CEST 2009


"mbikinyi brat" <mbikinyi_brat at yahoo.com> wrote 

> Here are two functions printme and change quite spaced apart. 

The spacing of the functions inside the source file has nothing 
to do with the output.

Python reads the input file, ignores any spacing and executes 
any lines it recognises as code.

> When executed the output in bold are joined. 
> What can I do so that the results are separate in two blocks?

If you want to separatye the output you need to insert some space. 
You are in complete control, the computer is not intelligent 
enough to deduce that you want the two outputs separated.
You need to tell it to print some empty space.

One way to do that is by printing newline charactrs('\n')
To print 5 newlines you can do this: print '\n' * 5

> #Now you can call printme function
> printme("I'm first call to user defined function!")
> printme("Again second call to the same function")

add 
print '\n' * 3 
here 

> #Function definition is here
> def changeme(mylist):

> print "valuse outside the function:", mylist
> print "values inside this function:", mylist


Should result in:
I'm first call to user defined function!
Again second call to the same function



valuse outside the function: [10, 20, 30]
values inside this function: [10, 20, 30]

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list