def fun(): statements . . return string_value
Note: The statements after the return statements are not executed.
How to return a string in Python Example
Simple example code. The following example function will return a string value.
def test_return(): str1 = 'nice' return str1 print(test_return())
Another example with parameter
def result(mark): grade = '' if mark >= 75: grade = "PASS" else: grade = "FAIL" return grade print(result(50))
Do comment if you have any doubts and suggestions on this Python string return code.
Note: IDE: PyCharm 2021.1.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.