function returns

Discussion in 'Python' started by Bart Nessux, Jul 12, 2004.

  1. Bart Nessux

    Bart Nessux Guest

    When one returns x from a function, is x available in other functions or
    scopes within Python? Also, does it matter ehat the type (str, int,
    float, list, etc.) of x is?
    Bart Nessux, Jul 12, 2004
    #1
    1. Advertising

  2. Bart Nessux

    steve holden Guest

    Bart Nessux wrote:
    > When one returns x from a function, is x available in other functions or
    > scopes within Python? Also, does it matter ehat the type (str, int,
    > float, list, etc.) of x is?


    When opne returns x from a function then x is a reference to a value,
    and as long as that reference is assigned to a name outside the function
    it will be "kept alive" - in other words, the scope of a value is
    dynamic, unlike the scope of names.

    Different calls to the same function are quite at liberty to return
    values of different types, although this would usually be considered a
    somewhat perverse way to behave.

    regards
    Steve
    steve holden, Jul 12, 2004
    #2
    1. Advertising

  3. steve holden wrote:
    > Bart Nessux wrote:
    > Different calls to the same function are quite at liberty to return
    > values of different types, although this would usually be considered a
    > somewhat perverse way to behave.


    I disagree about the last clause. One of the wonderful things about a
    dynamically typed language like Python is that one can pass, under the same
    parameter name, and return, different types to and from functions. I don't
    say it should always be done but it sure comes in handy when one does it,
    and it often simplifies code where the need to have different functions
    doing almost the same thing is no longer necessary.
    Edward Diener, Jul 13, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. vizlab
    Replies:
    3
    Views:
    4,172
    Michael Bar-Sinai
    Oct 17, 2007
  2. Boris Sargos
    Replies:
    3
    Views:
    376
    John Harrison
    Apr 23, 2004
  3. ++imanshu
    Replies:
    7
    Views:
    455
    ++imanshu
    Aug 23, 2008
  4. Trans
    Replies:
    2
    Views:
    211
    Trans
    Nov 6, 2005
  5. Srijayanth Sridhar
    Replies:
    19
    Views:
    595
    David A. Black
    Jul 2, 2008
Loading...

Share This Page