Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics (2015) Number Game App String length

What is meant by "return True"

How to assign a boolean value to the return? I want to do something like... return true

strlen.py
def just_right(yourString) :
  ysl = len(yourString)
  if ysl < 5 :
    return "Your string is too short"
  elif ysl > 5 :
    return "Your string is too long"
  else :
    return 

2 Answers

Work

def just_right(string):
  if len(string) < 5:
    return "Your string is too short"
  elif len(string) > 5:
    return "Your string is too long"
  else:
    return True
#The "return" statement
**********************
#return_stmt ::= "return" [expression_list]
#"return" may only occur syntactically nested in a function definition,
#not within a nested class definition.
#If an expression list is present, it is evaluated, else "None" is
#substituted.
#"return" leaves the current function call with the expression list (or
#"None") as return value.
#When "return" passes control out of a "try" statement with a "finally"
#clause, that "finally" clause is executed before really leaving the
#function.
#In a generator function, the "return" statement indicates that the
#generator is done and will cause "StopIteration" to be raised. The
#returned value (if any) is used as an argument to construct
#"StopIteration" and becomes the "StopIteration.value" attribute.
#In an asynchronous generator function, an empty "return" statement
#indicates that the asynchronous generator is done and will cause
#"StopAsyncIteration" to be raised.  A non-empty "return" statement is
#a syntax error in an asynchronous generator function.
#Related help topics: FUNCTIONS
Jakob Hansen
Jakob Hansen
13,746 Points

return True or False is a way to see if the function was succesful or not. fx

def checkName(name):
    if name == "John":
        return True
    else:
        return False