It is fun.the result of str.lower(str())

Discussion in 'Python' started by Sullivan WxPyQtKinter, Mar 7, 2006.

  1. Guess what would be the result of these functions:

    >>>str.lower('ASFA')
    >>>str.join(str(),['1','1','1'])
    >>>str.join('a','b')


    If you guess them correctly, please explain.
    Sullivan WxPyQtKinter, Mar 7, 2006
    #1
    1. Advertising

  2. "Sullivan WxPyQtKinter" wrote:

    > Guess what would be the result of these functions:
    >
    > >>>str.lower('ASFA')
    > >>>str.join(str(),['1','1','1'])
    > >>>str.join('a','b')

    >
    > If you guess them correctly, please explain.


    as I just said, I.method() and C.method(I) are equivalent,
    so that's just an odd way to write

    'ASFA'.lower()
    str().join(['1', '1', '1'])
    'a'.join('b')

    which, given that str() returns an empty string, and a string
    behaves like a sequence of individual characters, is equivalent
    to

    'ASFA'.lower() => 'asfa'
    ''.join(['1', '1', '1']) => '111'
    'a'.join(['b']) => 'b'

    </F>
    Fredrik Lundh, Mar 7, 2006
    #2
    1. Advertising

  3. Sullivan WxPyQtKinter

    Duncan Booth Guest

    Sullivan WxPyQtKinter wrote:

    > Guess what would be the result of these functions:
    >
    >>>>str.lower('ASFA')
    >>>>str.join(str(),['1','1','1'])
    >>>>str.join('a','b')

    >
    > If you guess them correctly, please explain.


    I think it was because I've read the manuals.
    Duncan Booth, Mar 7, 2006
    #3
  4. Sullivan WxPyQtKinter wrote:
    > Guess what would be the result of these functions:


    s/functions/method calls/

    >
    >>>>str.lower('ASFA')


    => 'ASFA'.lower() => 'asfa'

    >>>>str.join(str(),['1','1','1'])


    => ''.join(['1','1','1']) => '111'

    >>>>str.join('a','b')


    => 'a'.join('b') => 'b'

    >
    > If you guess them correctly,


    No need to guess, there's this thing named the python interactive shell,
    you know... And it even has an integrated help system.

    > please explain.


    Explain what ? It's all in the fine manual.

    * Klass() is a call to Klass's constructor and returns an instance of Klass.

    * Klass.method(klass_instance) is the same as klass_instance.method()
    * str is the builtin string class.
    * without any args, the str constructor returns an empty string
    * str.join() takes a sequence of strings and join'em with the target str
    instance as separator

    Now would you be kind enough to explain what's funny about all this ?

    --
    bruno desthuilliers
    python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
    p in ''.split('@')])"
    bruno at modulix, Mar 7, 2006
    #4
  5. On Tue, 07 Mar 2006 10:23:59 +0100, rumours say that bruno at modulix
    <> might have written:

    <snip various python expressions>

    >Now would you be kind enough to explain what's funny about all this ?


    I would guess it's the statement: "Funny, it works!"
    --
    TZOTZIOY, I speak England very best.
    "Dear Paul,
    please stop spamming us."
    The Corinthians
    Christos Georgiou, Mar 7, 2006
    #5
  6. Sullivan WxPyQtKinter

    Tim Roberts Guest

    "Sullivan WxPyQtKinter" <> wrote:
    >
    >Guess what would be the result of these functions:
    >
    >>>>str.lower('ASFA')
    >>>>str.join(str(),['1','1','1'])
    >>>>str.join('a','b')

    >
    >If you guess them correctly, please explain.


    Can you tell us what you expected these to do? It might help future
    questioners.
    --
    - Tim Roberts,
    Providenza & Boekelheide, Inc.
    Tim Roberts, Mar 9, 2006
    #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. Andy Fish
    Replies:
    65
    Views:
    1,706
    Mabden
    May 18, 2004
  2. dolphin
    Replies:
    4
    Views:
    312
    Jorgen Grahn
    Aug 25, 2007
  3. er
    Replies:
    2
    Views:
    488
  4. Frank Millman

    Fun with 'str' and 'bytes'

    Frank Millman, Mar 4, 2011, in forum: Python
    Replies:
    3
    Views:
    401
    Terry Reedy
    Mar 7, 2011
  5. Michael Tan
    Replies:
    32
    Views:
    940
    Ara.T.Howard
    Jul 21, 2005
Loading...

Share This Page