🌐
Stack Overflow
stackoverflow.com › questions › 56484258 › returning-a-string-in-python
Returning a string in python - Stack Overflow
the caller script just need to print the return string. It's just a print statement: Copyprint utils.test_return · Actual result: <function test_return at 0x7f9cff9d8a28> Expected result: nice · python · Share · Share a link to this question · Copy linkCC BY-SA 4.0 ·
Discussions

How to write a function that returns a simple string value
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 ... More on discuss.python.org
🌐 discuss.python.org
0
October 11, 2022
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
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
Python: can a function return a string? - Stack Overflow
I am making a recursive function that slices string until it is empty. When it is empty it alternatively selects the characters and is supposed to print or return the value. In this case I am expec... More on stackoverflow.com
🌐 stackoverflow.com
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-return-statement
Python return statement | DigitalOcean
August 3, 2022 - Python Return Boolean · Let’s look at an example where our function will return the string representation of the argument. We can use the str() function to get the string representation of an object.
🌐
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...
🌐
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. Remember that Python is case-sensitive, so it matters whether you type a capital or lowercase letter in all of your symbols.
🌐
Python documentation
docs.python.org › 3 › library › functions.html
Built-in Functions — Python 3.14.3 documentation
3 days ago - Added in version 3.2: This function was first removed in Python 3.0 and then brought back in Python 3.2. ... Return the string representing a character with the specified Unicode code point.
🌐
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.
🌐
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).
Find elsewhere
🌐
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.
🌐
Python documentation
docs.python.org › 3 › library › typing.html
typing — Support for type hints
4 days ago - The Python runtime does not enforce function and variable type annotations. They can be used by third party tools such as type checkers, IDEs, linters, etc. This module provides runtime support for type hints. ... def surface_area_of_cube(edge_length: float) -> str: return f"The surface area of the cube is {6 * edge_length ** 2}."
🌐
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
Python Return Statement - Syntax, Usage, and Examples
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....
🌐
Python documentation
docs.python.org › 3 › tutorial › inputoutput.html
7. Input and Output — Python 3.14.3 documentation
To read a file’s contents, call f.read(size), which reads some quantity of data and returns it as a string (in text mode) or bytes object (in binary mode). size is an optional numeric argument. When size is omitted or negative, the entire contents of the file will be read and returned; it’s your problem if the file is twice as large as your machine’s memory.
🌐
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.
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.
🌐
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.
🌐
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.
🌐
Python.org
discuss.python.org › ideas
Space between "return" and string - Ideas - Discussions on Python.org
January 22, 2024 - When a function in Python returns a string, the string can be directly connected after “return”. The following is an error example: def foo(): return"Foo" This way of writing is extremely irregular, but it can stil…
🌐
CodeBasics
code-basics.com › programming › python course › return values
Return values | Python | CodeBasics
[Python] — Return values — In this lesson, we'll take a closer look at how to work with functions we've created to make them useful. When we define a function, it prints data on the screen: ```python def greeting()...