Question on Python Function
joy99
subhakolkata1234 at gmail.com
Mon May 24 17:39:09 EDT 2010
On May 25, 1:56 am, Vlastimil Brom <vlastimil.b... at gmail.com> wrote:
> 2010/5/24 joy99 <subhakolkata1... at gmail.com>:
>
>
>
>
>
>
>
> > Dear Group,
>
> > I have a small question on function.
>
> > If I write two functions like the following:
>
> > IDLE 2.6.5
> >>>> def function1(n):
> > element1=5
> > element2=6
> > add=element1+element2
> > print "PRINT THE ADDITION",add
>
> >>>> def function2(n):
> > element3=7
> > element4=22
> > mult=element3*element4
> > print "PRINT THE MULTIPLICATION",mult
>
> > Can I now write a third function where the above two functions can be
> > passed as argument or parameter?
>
> > Best Regards,
> > Subhabrata.
>
> > NB: As I copied the code from IDLE to MS-Word befor posting here,
> > codes may have slight indentation errors.
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
> Hi,
> while it is quite unclear to me, what you are trying to achieve (what
> are the passed n arguments supposed to do?), you can well pass an
> already defined function as an argument to another function; if you
> want to select a function for the needed operation, if can be e.g.:
>
> def compute(arg1, arg2, fn):
> fn(arg1, arg2)
>
> - supposing you don't want to "return" the result but just print it as
> your functions do;
> is it what you were after or did I miss something more complex?
>
> hth
> vbr- Hide quoted text -
>
> - Show quoted text -
Dear Vlastimil,
You are right. Your approach will do to me. I was trying Python Doc
either I do not know where to check, or I could not find.
I am trying to work out. Numbers I can pass, I was checking the last
example in Python Docs with "def cheeseshop(kind, *arguments,
**keywords):" if that gives me any clue.
If you can kindly try.
Best Regards,
Subhabrata.
More information about the Python-list
mailing list