Python 2.7 返回def段落中的变量

Python 2.7 返回def段落中的变量,python-2.7,Python 2.7,为什么python不在def段落中返回变量?如果在def段落中不起作用,它也会起作用 这是我的密码: def find_message(text): t=''.join([c for c in text if c.isupper()]) return t find_message("How are you? Eh, ok. Low or Lower? Ohhh.") 它没有返回任何内容,但如果在不使用def的情况下运行相同的内容,则效果良好: s = 'How are you

为什么python不在def段落中返回变量?如果在def段落中不起作用,它也会起作用

这是我的密码:

def find_message(text):
    t=''.join([c for c in text if c.isupper()])
    return t

find_message("How are you? Eh, ok. Low or Lower? Ohhh.")
它没有返回任何内容,但如果在不使用def的情况下运行相同的内容,则效果良好:

s = 'How are you? Eh, ok. Low or Lower? Ohhh.'
t=''.join([c for c in s if c.isupper()])
print t

请帮忙,谢谢

我知道这听起来很愚蠢,但也许这样行得通

def find_message(text):
   t=''.join([c for c in text if c.isupper()])
   return t

# IMPORTANT! Print returned message
print find_message("How are you? Eh, ok. Low or Lower? Ohhh.")

我认为这是正确的,假设您将上述代码作为脚本运行,而不是以交互方式运行。它正在返回,您只需对返回的值不做任何操作!