Is there a .tolower() for a string??

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Amy

    #1

    Is there a .tolower() for a string??

    I have a string say

    a = "Hello how are YOU"

    I want to end up with

    a = "hello how are you'

    Isn't there a built in method for changing a string to lowercase?

    Thanks.
  • KefX

    #2
    Re: Is there a .tolower() for a string??

    >Isn't there a built in method for changing a string to lowercase?

    "If you can't find it, it's probably in section two of the library docs."
    (Hint: strings are a sequence type.)

    - Kef

    Comment

    • Mark Hahn

      #3
      Re: Is there a .tolower() for a string??

      [color=blue]
      > I have a string say
      >
      > a = "Hello how are YOU"
      >
      > I want to end up with
      >
      > a = "hello how are you'
      >
      > Isn't there a built in method for changing a string to lowercase?
      >[/color]
      [color=blue][color=green][color=darkred]
      >>> 'aBc'.lower()[/color][/color][/color]
      'abc'


      Comment

      • Colin Brown

        #4
        Re: Is there a .tolower() for a string??


        "Amy" <sean_bear@hotm ail.com> wrote in message
        news:7b1fa3cb.0 311261057.ecb73 25@posting.goog le.com...[color=blue]
        > I have a string say
        >
        > a = "Hello how are YOU"
        >
        > I want to end up with
        >
        > a = "hello how are you'
        >
        > Isn't there a built in method for changing a string to lowercase?
        >
        > Thanks.[/color]

        a.lower()



        Comment

        • Peter Otten

          #5
          Re: Is there a .tolower() for a string??

          Amy wrote:
          [color=blue]
          > I have a string say
          >
          > a = "Hello how are YOU"
          >
          > I want to end up with
          >
          > a = "hello how are you'
          >
          > Isn't there a built in method for changing a string to lowercase?[/color]

          dir("")

          will give you all str attributes. The most promising is lower, so let's try:
          [color=blue][color=green][color=darkred]
          >>> a = "LOWER"
          >>> a.lower()[/color][/color][/color]
          'lower'[color=blue][color=green][color=darkred]
          >>> a[/color][/color][/color]
          'LOWER'

          You might not have expected the last outcome. This is because the lower()
          method does not change the original string but creates a new one that is
          all lowercase. Strings are "immutable" , i. e. cannot be changed once they
          are created. To get the desired effect, you need to "rebind" a:
          [color=blue][color=green][color=darkred]
          >>> a = a.lower()
          >>> a[/color][/color][/color]
          'lower'

          Peter

          Comment

          • Arnaud-F. FAUSSE

            #6
            Re: Is there a .tolower() for a string??

            look at .lower()
            I hope it helps
            AF

            "Amy" <sean_bear@hotm ail.com> a écrit dans le message de
            news:7b1fa3cb.0 311261057.ecb73 25@posting.goog le.com...[color=blue]
            > I have a string say
            >
            > a = "Hello how are YOU"
            >
            > I want to end up with
            >
            > a = "hello how are you'
            >
            > Isn't there a built in method for changing a string to lowercase?
            >
            > Thanks.[/color]


            Comment

            • Wojtek Walczak

              #7
              Re: Is there a .tolower() for a string??

              Dnia 26 Nov 2003 10:57:32 -0800, Amy napisa³(a):
              [...][color=blue]
              > Isn't there a built in method for changing a string to lowercase?[/color]
              [color=blue][color=green][color=darkred]
              >>> print ''.lower.__doc_ _[/color][/color][/color]
              S.lower() -> string

              Return a copy of the string S converted to lowercase.


              Read the docs!

              --
              [ Wojtek Walczak - gminick (at) underground.org .pl ]
              [ <http://gminick.linuxse curity.pl/> ]
              [ "...rozmait e zwroty, matowe od patyny dawnosci." ]

              Comment

              • Duncan Booth

                #8
                Re: Is there a .tolower() for a string??

                Wojtek Walczak <gminick@hacker .pl> wrote in
                news:bq345v$97s $1@nemesis.news .tpi.pl:
                [color=blue]
                > Dnia 26 Nov 2003 10:57:32 -0800, Amy napisa³(a):
                > [...][color=green]
                >> Isn't there a built in method for changing a string to lowercase?[/color]
                >[color=green][color=darkred]
                >>>> print ''.lower.__doc_ _[/color][/color]
                > S.lower() -> string
                >
                > Return a copy of the string S converted to lowercase.
                >
                >
                > Read the docs![/color]

                Also, you could have said 'learn to use the help command, its more
                convenient than printing __doc__':
                [color=blue]
                >[color=green][color=darkred]
                >>>> help("".lower)[/color][/color]
                >Help on built-in function lower:
                >
                >lower(...)
                > S.lower() -> string
                >
                > Return a copy of the string S converted to lowercase.
                >[/color]

                Another command the OP might have found useful would be help(""), or
                help(str) which tell you all about the string methods.

                --
                Duncan Booth duncan@rcp.co.u k
                int month(char *p){return(1248 64/((p[0]+p[1]-p[2]&0x1f)+1)%12 )["\5\x8\3"
                "\6\7\xb\1\x9\x a\2\0\4"];} // Who said my code was obscure?

                Comment

                Working...