(Updated answer for fstrings) For big string like what you have do a few things.

First use """ """ instead of trying to build it the way you are.

You should then use preferably fstrings (Python 3.6+)

return f"""The GC content for non retained introns is {avg_gc(nr)}
The GC content for retained introns is {avg_gc(r)}
The average length of non retained introns is {intlength(nr)}
The average length of retained introns is {intlength(r)}
The percent of non retained introns divisible by 3 is {intdiv(nr)}
The percent of retained introns divisible by 3 is {intdiv(r)}.
"""

Older versions of Python can use:

return """The GC content for non retained introns is {nr_gc}
The GC content for retained introns is {r_gc}
The average length of non retained introns is {nr_avglen}
The average length of retained introns is {r_avglen}
The percent of non retained introns divisible by 3 is {nr_percdiv}
The percent of retained introns divisible by 3 is {r_percdiv}.
""".format(r_gc = avg_gc(r),
           nr_gc = avg_gc(nr),
           r_avglen = intlength(r),
           nr_avglen = intlength(nr),
           r_percdiv = intdiv(r)
           nr_percdiv = intdiv(nr))
Answer from Michael Robellard on Stack Overflow
๐ŸŒ
Real Python
realpython.com โ€บ python-return-statement
The Python return Statement: Usage and Best Practices โ€“ Real Python
June 14, 2024 - This can be any data type, such as a number, string, list, or object. To return multiple values, list them after the return keyword separated by commas. Python packs these values into a tuple.
๐ŸŒ
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.
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ python-return-statement
Python return statement | DigitalOcean
August 3, 2022 - The python return statement is used to return values from the function. We can use the return statement in a function only.
๐ŸŒ
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...
๐ŸŒ
Finxter
blog.finxter.com โ€บ python-return-string-from-function
Python Return String From Function โ€“ Be on the Right Side of Change
def create_string(): ''' Function to return string ''' my_string = '' for i in range(10): my_string += str(i) return my_string s = create_string() print(s) # 0123456789 ยท Note that you store the resulting string in the variable s. The local variable my_string that you created within the function body is only visible within the function but not outside of it. So, if you try to access the name my_string, Python will raise a NameError:
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python
How to Return Multiple Values from a Function in Python | note.nkmk.me
April 23, 2025 - You can unpack multiple return values and assign them to separate variables. ... The same applies to three or more return values. def test2(): return 'abc', 100, [0, 1, 2] a, b, c = test2() print(a) # abc print(b) # 100 print(c) # [0, 1, 2] ... By using [], you can return a list instead of a tuple. def test_list(): return ['abc', 100] result = test_list() print(result) print(type(result)) # ['abc', 100] # <class 'list'> ... Draw circle, rectangle, line, etc. with Python, Pillow
Find elsewhere
๐ŸŒ
EyeHunts
tutorial.eyehunts.com โ€บ home โ€บ how to return a string in python | example code
How to return a string in Python | Example code - EyeHunts
March 10, 2022 - The following example function will return a string value. def test_return(): str1 = 'nice' return str1 print(test_return()) ... def result(mark): grade = '' if mark >= 75: grade = "PASS" else: grade = "FAIL" return grade print(result(50)) ... ...
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 58509098 โ€บ need-help-returning-a-string-with-multiple-variables-in-python
Need help returning a string with multiple variables in Python - Stack Overflow
def report_stats(total_cost,gallons_used): global total_distance global net_miles var1 = "Total Miles Traveled: ", total_distance var2 = "Net Miles: ", net_miles var3 = "Gallons used: ", gallons_used var4 = "Total Cost: ", total_cost if total_cost < 25: how_much = "Cha Chiiinng!" if 25 <= total_cost < 100: how_much = "Wallet getting nervous!" else: how_much = "Ouch!" return var1,var2,var3,var4,how_much var1,var2,var3,var4,how_much = report_stats(total_cost,gallons_used) print(var1 + '\n' + var2 + '\n' + var3 + '\n' + var4 + '\n' + how_much') ... Your vars should probably be strings (now they are tuples). Change that and use Python's triple quotes, as shown below:
๐ŸŒ
Mimo
mimo.org โ€บ glossary โ€บ python โ€บ return
Python Return Statement - Syntax, Usage, and Examples
This value can then be stored in a variable or used directly. Implicitly Returns None: If a function completes without hitting a return statement, it automatically returns the special value None. Can Return Any Data Type: A function can return a string, number, list, dictionary, object, or even another function. Return Multiple Values with Tuples: To return multiple values, simply list them after the return keyword, separated by commas (e.g., return a, b, c). Python ...
๐ŸŒ
Codecademy Forums
discuss.codecademy.com โ€บ frequently asked questions โ€บ python faq
How can I return a string of my carโ€™s instance variables? - Python FAQ - Codecademy Forums
February 13, 2018 - Question How can I return a string of my carโ€™s instance variables? Answer Recall that to print a string containing variables, itโ€™s easy to use string formatting using the %s placeholder, followed by a % (list, of, variables) after the string.
๐ŸŒ
Data Science for Everyone
matthew-brett.github.io โ€บ teaching โ€บ string_formatting.html
Inserting values into strings โ€” Tutorials on imaging, computing and mathematics
This prints a floating point value (f) with exactly 4 digits after the decimal point: >>> 'A formatted number - {:.4f}'.format(.2) 'A formatted number - 0.2000' See the Python string formatting documentation for more details and examples. If you can depend on having Python >= version 3.6, then you have another attractive option, which is to use the new formatted string literal (f-string) syntax to insert variable values.
๐ŸŒ
Runestone Academy
runestone.academy โ€บ ns โ€บ books โ€บ published โ€บ fopp โ€บ Functions โ€บ Returningavaluefromafunction.html
12.5. Returning a value from a function โ€” Foundations of Python Programming
Youโ€™ll want to iterate over all ... of the strings. As soon as you get to one name that is longer than five letters, you know the function should return True โ€“ yes, there is at least one name longer than five letters! And if you go through the whole list and there was no name longer than five letters, then the function should return False. ... So far, we have just seen return values being assigned to variables. For example, we had the line squareResult = square(toSquare). As with all assignment ...
๐ŸŒ
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 - This was the question I tried this ... problem with it? ... 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. A variable named example ...
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-print-variable-how-to-print-a-string-and-variable
Python Print Variable โ€“ How to Print a String and Variable
December 7, 2021 - I add the strings in double quotes and the variable name without any surrounding it, using the addition operator to chain them all together: fave_language = "Python" print("I like coding in " + fave_language + " the most") #output #I like coding in Python the most
๐ŸŒ
Boot.dev
boot.dev โ€บ lessons โ€บ 3c5fe40f-41e3-4d7e-a035-be67c8d83536
Learn to Code in Python: Multiple Return Values | Boot.dev
A function can return more than one value by separating them with commas. def cast_iceblast(wizard_level, start_mana): damage = wizard_level * 2 new_mana = start_mana - 10 return damage, new_mana # return two values ยท When calling a function that returns multiple values, you can assign them to multiple variables.