简体   繁体   中英

How do I define a function that returns my string in lower case?

I am trying to define a function that makes a string of text inputed into lowercase.

def lowercase(text:str):
     text.lower()
     return text

Once I put my test sentence into this function, it still prints out uppercase letters.

.lower() returns a new value, therefor you need to store it in a variable or directly return this.

def lowercase(text:str):
     text = text.lower()
     return text

or

def lowercase(text:str):
     return text.lower()
def lowercase(text:str):
     return text.lower()

This should do it.

Try this:

def lower(text):
    lowered = text.lower()
    return lowered

You were returning text which was the input of the function, so the function returned the text which it received as input.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM