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

A

Amy

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.
 
K

KefX

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
 
M

Mark Hahn

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?
'abc'
 
C

Colin Brown

Amy said:
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.

a.lower()
 
P

Peter Otten

Amy said:
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?

dir("")

will give you all str attributes. The most promising is lower, so let's try:
'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:
'lower'

Peter
 
W

Wojtek Walczak

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

Return a copy of the string S converted to lowercase.


Read the docs!
 
D

Duncan Booth

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

Return a copy of the string S converted to lowercase.


Read the docs!

Also, you could have said 'learn to use the help command, its more
convenient than printing __doc__':
Help on built-in function lower:

lower(...)
S.lower() -> string

Return a copy of the string S converted to lowercase.

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top