big letter -> small letter

Discussion in 'Python' started by vertigo, Jul 6, 2004.

  1. vertigo

    vertigo Guest

    Hello
    How can i change big letter to small letter ?

    When i tried char=char+32 i received error that can not add int to sring.

    Thanx
    Michal
     
    vertigo, Jul 6, 2004
    #1
    1. Advertising

  2. vertigo wrote:
    > Hello
    > How can i change big letter to small letter ?
    >
    > When i tried char=char+32 i received error that can not add int to sring.


    That's C thinking, you have to get away from that ;)

    In Python, there is no "char" type. Every char is a string, and you
    can't add an integer to a string.

    But, luckily, everything is an object, too, and has useful methods to do
    something with the object. In case of your problem, that would be

    char = char.lower()

    Reinhold

    --
    Wenn eine Linuxdistribution so wenig brauchbare Software wie Windows
    mitbrächte, wäre das bedauerlich. Was bei Windows der Umfang eines
    "kompletten Betriebssystems" ist, nennt man bei Linux eine Rescuedisk.
    -- David Kastrup in de.comp.os.unix.linux.misc
     
    Reinhold Birkenfeld, Jul 6, 2004
    #2
    1. Advertising

  3. vertigo wrote:
    > Hello
    > How can i change big letter to small letter ?
    >
    > When i tried char=char+32 i received error that can not add int to sring.


    Which is ofcourse, correct behavior. You cannot add numbers to strings.

    Use the tolower string method. It even works on strings of length >1:

    >>> print "BiGLeTtEr".lower()

    bigletter

    There's also an upper().

    --Irmen
     
    Irmen de Jong, Jul 6, 2004
    #3
  4. vertigo

    Bernd Kaiser Guest

    vertigo wrote:
    > Hello
    > How can i change big letter to small letter ?
    >
    > When i tried char=char+32 i received error that can not add int to sring.
    >
    > Thanx
    > Michal
    >

    Check out the String Modul
    http://python.org/doc/2.3.4/lib/module-string.html

    Redards,
    Bernd
     
    Bernd Kaiser, Jul 6, 2004
    #4
  5. Bernd Kaiser wrote:
    > vertigo wrote:
    >> Hello
    >> How can i change big letter to small letter ?
    >>
    >> When i tried char=char+32 i received error that can not add int to sring.
    >>
    >> Thanx
    >> Michal
    >>

    > Check out the String Modul
    > http://python.org/doc/2.3.4/lib/module-string.html


    Caution! Always use the functions of the str object itself, not the
    correspondig method of the string module because the former is quicker.
    There are cases where you need the string module, but they have become rare.

    Instead of "string.upper(s)" use "s.upper()"

    Reinhold

    --
    Wenn eine Linuxdistribution so wenig brauchbare Software wie Windows
    mitbrächte, wäre das bedauerlich. Was bei Windows der Umfang eines
    "kompletten Betriebssystems" ist, nennt man bei Linux eine Rescuedisk.
    -- David Kastrup in de.comp.os.unix.linux.misc
     
    Reinhold Birkenfeld, Jul 6, 2004
    #5
    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. Tony Meyer

    RE: big letter -> small letter

    Tony Meyer, Jul 6, 2004, in forum: Python
    Replies:
    0
    Views:
    509
    Tony Meyer
    Jul 6, 2004
  2. Andrew McNamara

    Re: big letter -> small letter

    Andrew McNamara, Jul 6, 2004, in forum: Python
    Replies:
    2
    Views:
    756
    Scott David Daniels
    Jul 6, 2004
  3. Shaguf
    Replies:
    0
    Views:
    374
    Shaguf
    Dec 24, 2008
  4. Shaguf
    Replies:
    0
    Views:
    463
    Shaguf
    Dec 26, 2008
  5. Shaguf
    Replies:
    0
    Views:
    250
    Shaguf
    Dec 26, 2008
Loading...

Share This Page