Values are not returned just to do calculations, that's just one example of what you can do. The return statement is essentially just a reverse example of passing an argument into a function. The function is giving a value back to the code that called it and once returned the value can be used for anything that value normally could be. Let's say you had a function that was designed to present the user with a list of options and then asked the user to choose one of them. That function would not be very useful if i did not tell the code that called it what the user actually ended up choosing, which it can easily do by returning the choice. Also consider built-in methods in Python like upper (uppercase a string) and lower (lowercase a string) those are methods that take a string and then returns a string that has had specific formatting applied to it. They would not serve much use if they did not ultimately return the string they created from the string you called them on. You can return literally any value in Python, not just strings and numbers. And as you get farther into the courses you'll start to get a better understand of why that is a useful. There are many functions where the function serves no real purpose if it does not actually return the value it worked on after it has finished. As for your question on code formatting, there is a link below the box where you write your comment labeled "Markdown Cheatsheet" which when clicked opens up a window with various formatting tips. For code formatting you simply need to write three backticks ``` then the name of the language you are embedding followed by a new line. Then paste in your code, then on a new line below your code enter three more backticks. Answer from andren on teamtreehouse.com
🌐
Google
developers.google.com › google for education › python › python strings
Python Strings | Python Education | Google for Developers
Python does not have a separate character type. Instead an expression like s[8] returns a string-length-1 containing the character. With that string-length-1, the operators ==, <=, ...
🌐
Python
docs.python.org › 3 › library › string.html
string — Common string operations
The return value used_key has the same meaning as the key parameter to get_value(). ... Retrieve a given field value. The key argument will be either an integer or a string.
Discussions

Why return a string?
I think you understanding the return ... for returning strings. For code sharing and other "Markdown" in your post, checkout the "Markdown Cheatsheet" link under the textarea. When I want to insert code, like the example below, Use 3 lines. Line 1 - Three backtics (- key to the left of the 1 and above the tab on a standard us keyboard) and language (like python) Line 2 - ... More on teamtreehouse.com
🌐 teamtreehouse.com
1
May 13, 2018
For a function, how to make the function result return (String)
If you look in your elif statement, you wrote String with a capital "S", but the parameter's name is "string" with a lowercase "s". Also, you'll need to capitalize the "Y" in "Your" at the beginning of both strings you're returning. That's not Python caring about case there, because it's in ... More on teamtreehouse.com
🌐 teamtreehouse.com
1
August 9, 2017
Function returning a string
You are returning a tuple, not a string. If you want to return a string, build one using string formatting. My preferred method is with f-strings. You would return f'{x} minutes is {hours} hours', where the variables are passed to the string in the curly brackets. More on reddit.com
🌐 r/learnpython
11
6
January 30, 2022
Returning a string in python - Stack Overflow
I need to get a string returned to the calling function of a script. A module called 'utils' has the function being called for a return value. Trying to learn how exactly this works/what should be More on stackoverflow.com
🌐 stackoverflow.com
🌐
Real Python
realpython.com › python-return-statement
The Python return Statement: Usage and Best Practices – Real Python
June 14, 2024 - In Python, the return statement allows you to send values back to the caller from a function. To return a single value, use the return keyword followed by the value. This can be any data type, such as a number, string, list, or object.
Top answer
1 of 1
1
Values are not returned just to do calculations, that's just one example of what you can do. The return statement is essentially just a reverse example of passing an argument into a function. The function is giving a value back to the code that called it and once returned the value can be used for anything that value normally could be. Let's say you had a function that was designed to present the user with a list of options and then asked the user to choose one of them. That function would not be very useful if i did not tell the code that called it what the user actually ended up choosing, which it can easily do by returning the choice. Also consider built-in methods in Python like upper (uppercase a string) and lower (lowercase a string) those are methods that take a string and then returns a string that has had specific formatting applied to it. They would not serve much use if they did not ultimately return the string they created from the string you called them on. You can return literally any value in Python, not just strings and numbers. And as you get farther into the courses you'll start to get a better understand of why that is a useful. There are many functions where the function serves no real purpose if it does not actually return the value it worked on after it has finished. As for your question on code formatting, there is a link below the box where you write your comment labeled "Markdown Cheatsheet" which when clicked opens up a window with various formatting tips. For code formatting you simply need to write three backticks ``` then the name of the language you are embedding followed by a new line. Then paste in your code, then on a new line below your code enter three more backticks.
🌐
W3Schools
w3schools.com › python › python_howto_reverse_string.asp
How to reverse a String in Python
If you like to have a function where you can send your strings, and return them backwards, you can create a function and insert the code from the example above.
🌐
Python documentation
docs.python.org › 3 › library › stdtypes.html
Built-in Types — Python 3.14.3 documentation
3 days ago - Some operations are supported by several object types; in particular, practically all objects can be compared for equality, tested for truth value, and converted to a string (with the repr() function or the slightly different str() function).
🌐
Team Treehouse
teamtreehouse.com › community › for-a-function-how-to-make-the-function-result-return-string
For a function, how to make the function result return (String) (Example) | Treehouse Community
August 9, 2017 - 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 ... You have a small typo in your elif statement.
Find elsewhere
🌐
Python documentation
docs.python.org › 3 › library › functions.html
Built-in Functions — Python 3.14.3 documentation
3 days ago - Equivalent to: def any(iterable): for element in iterable: if element: return True return False ... As repr(), return a string containing a printable representation of an object, but escape the non-ASCII characters in the string returned by ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-string
Python String - GeeksforGeeks
Python provides various built-in methods to manipulate strings. Below are some of the most useful methods: 1. len(): The len() function returns the total number of characters in a string (including spaces and punctuation).
Published   January 14, 2026
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-str-repr-functions
How To Use the __str__() and __repr__() Methods in Python | DigitalOcean
October 8, 2025 - A: In the Python REPL (interactive ... the object’s structure and state during interactive sessions. A: Make __repr__() return a string that looks like a valid Python expression to recreate the object....
🌐
W3Schools
w3schools.com › python › python_ref_string.asp
Python String Methods
Python has a set of built-in methods that you can use on strings. Note: All string methods returns new values.
🌐
Stack Overflow
stackoverflow.com › questions › 56484258 › returning-a-string-in-python
Returning a string in python - Stack Overflow
@FutureB the parenthesis are the only way to call the function. Without it only the function object is returned. But you could achieve this by setting a variable in utils. test_return = "nice" ... If you want that, try Ruby instead of Python.
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-return-statement
Python return statement | DigitalOcean
August 3, 2022 - We will use bool() function to get the boolean value of the object. def bool_value(x): return bool(x) print(f'Boolean value returned by bool_value(False) is {bool_value(False)}') print(f'Boolean value returned by bool_value(True) is {bool_value(True)}') print(f'Boolean value returned by ...
🌐
Python.org
discuss.python.org › python help
How to write a function that returns a simple string value - Python Help - Discussions on Python.org
October 11, 2022 - Help please. I have to write a simple function that returns a string. The string (in this example) is a city and a country e.g. London, England I have done some other exercises where I return a formatted name e.g. Bob Johnson, but I cannot get this one right Here is my codes so far: def city_country(city_name, country_name): """Return a string value of information about a city and country.""" location = f"{city_name} {country_name}" return location location = city_country('Santiago', 'Chi...
🌐
SmartBear Community
community.smartbear.com › smartbear community › testcomplete › testcomplete questions
Return a string in a script | SmartBear Community
April 17, 2023 - I wrote a small script in Python that generates a string of 8 digits. I am trying to set this up so that I run the script in a KeyWord test and the value...
🌐
Python documentation
docs.python.org › 3 › library › re.html
re — Regular expression operations
Perform the same operation as sub(), but return a tuple (new_string, number_of_subs_made). The expression’s behaviour can be modified by specifying a flags value. Values can be any of the flags variables, combined using bitwise OR (the | operator). ... Escape special characters in pattern. This is useful if you want to match an arbitrary literal string that may have regular expression metacharacters in it.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-return-statement
Python return statement - GeeksforGeeks
December 20, 2025 - The return statement is used inside a function to send a value back to the place where the function was called. Once return is executed, the function stops running, and any code written after it is ignored.
🌐
Quora
quora.com › How-do-I-return-a-string-in-Python
How to return a string in Python - Quora
Answer (1 of 14): I recommend to use python “typing” module to ensure that you are not struggling with your casts. Here is an example: [code]import typing def func_name(var1: str, var: str ) -> str: return var1 + var2 [/code]Reference typing module for proper control of variables and generics.
🌐
Mimo
mimo.org › glossary › python › return
Mimo: The coding platform you need to learn Web Development, Python, and more.
def validate_age(age): # validate ... True # if none of the conditions trigger, return True · When returning strings, you can join elements with commas to create formatted output....