Is there a built-in method for transforming (1,None,"Hello!") to 1,None,"Hello!"?

Discussion in 'Python' started by Daniel Crespo, Nov 11, 2005.

  1. Is there a built-in method for transforming (1,None,"Hello!") to
    1,None,"Hello!"?

    Thanks
     
    Daniel Crespo, Nov 11, 2005
    #1
    1. Advertising

  2. On 2005-11-11, Daniel Crespo <> wrote:
    > Is there a built-in method for transforming (1,None,"Hello!") to
    > 1,None,"Hello!"?


    What transformation? The two are identical:

    >>> x = (1,None,"Hello!")
    >>> y = 1,None,"Hello!"
    >>> x == y

    True

    --
    Grant Edwards grante Yow! Nice decor!
    at
    visi.com
     
    Grant Edwards, Nov 11, 2005
    #2
    1. Advertising

  3. Daniel Crespo

    Guest

    do you mean this ? otherwise, don't know what you want.

    a, b, c = (1, None, "Hello!")

    Daniel Crespo wrote:
    > Is there a built-in method for transforming (1,None,"Hello!") to
    > 1,None,"Hello!"?
    >
    > Thanks
     
    , Nov 11, 2005
    #3
  4. Re: Is there a built-in method for transforming (1, None,"Hello!") to 1, None, "Hello!"?

    On 11 Nov 2005 07:21:46 -0800, Daniel Crespo <> wrote:
    > Is there a built-in method for transforming (1,None,"Hello!") to
    > 1,None,"Hello!"?


    There's no conversion to do:

    >>> (1,None,"Hello!")

    (1, None, 'Hello!')
    >>> 1,None,"Hello!"

    (1, None, 'Hello!')

    They are both tuples contining identicle elements. What is it that you
    want to do?

    --
    Cheers,
    Simon B,
    ,
    http://www.brunningonline.net/simon/blog/
     
    Simon Brunning, Nov 11, 2005
    #4
  5. Daniel Crespo <> wrote:

    > Is there a built-in method for transforming (1,None,"Hello!") to
    > 1,None,"Hello!"?


    You're mentioning two different literal syntaxes for the same object (a
    tuple) -- the one with parentheses works everywhere, the other one
    _almost_ everywhere (not where parentheses would be ambiguous).

    Not sure, therefore, what you mean by "transforming" here; if you're
    dealing with a string for in either case, for example, you could remove
    the first and last characters by slicing with [1:-1], etc, etc. Perhaps
    you can clarify exactly what you're asking for!


    Alex
     
    Alex Martelli, Nov 11, 2005
    #5
  6. Daniel Crespo

    Amaury Guest

    Re: Is there a built-in method for transforming (1,None,"Hello!")to 1,None,"Hello!"?

    Hello,

    Daniel Crespo wrote:
    > Is there a built-in method for transforming (1,None,"Hello!") to
    > 1,None,"Hello!"?


    As others answered before, the two syntaxes build the same object, so
    there is no need to convert.

    Except if you already have the tuple stored in a variable, and want to
    call a function with the tree arguments:
    args = (1,None,"Hello!")

    func(args) # equivalent to func((1,None,"Hello!"))
    func(*args) # equivalent to func(1,None,"Hello!")

    Note the '*' on the second call, it will flatten the args, and 3
    arguments are passed to the function.

    --
    Amaury
     
    Amaury, Nov 13, 2005
    #6
    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. Roy
    Replies:
    6
    Views:
    618
    Roedy Green
    Jan 7, 2008
  2. length power
    Replies:
    2
    Views:
    78
    Rustom Mody
    Apr 10, 2014
  3. Skip Montanaro
    Replies:
    0
    Views:
    60
    Skip Montanaro
    Apr 10, 2014
  4. Johannes Schneider

    Re: why i have the output of [None, None, None]

    Johannes Schneider, Apr 10, 2014, in forum: Python
    Replies:
    0
    Views:
    52
    Johannes Schneider
    Apr 10, 2014
  5. Terry Reedy
    Replies:
    0
    Views:
    62
    Terry Reedy
    Apr 10, 2014
Loading...

Share This Page