469,923 Members | 1,164 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,923 developers. It's quick & easy.

big letter -> small letter

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

Jul 18 '05 #1
4 3542
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
Jul 18 '05 #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.

Thanx
Michal

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

Redards,
Bernd
Jul 18 '05 #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
Jul 18 '05 #4
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
Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Paul Gorodyansky | last post: by
17 posts views Thread by cpptutor2000 | last post: by
17 posts views Thread by Cralis | last post: by
11 posts views Thread by Gerald I. Evenden | last post: by
13 posts views Thread by umpsumps | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.