[英]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.我正在尝试定义一个 function ,它将一串文本输入小写。
def lowercase(text:str):
text.lower()
return text
Once I put my test sentence into this function, it still prints out uppercase letters.一旦我将我的测试语句放入这个 function,它仍然会打印出大写字母。
.lower()
returns a new value, therefor you need to store it in a variable or directly return this. .lower()
返回一个新值,因此您需要将其存储在变量中或直接返回它。
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.您返回的
text
是 function 的输入,因此 function 返回了它作为输入接收的文本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.