About 14,100,000 results
Open links in new tab
  1. python - How do I get ("return") a result (output) from a function

    You can use the return statement to return a value from a function, this does not make it so that the returned variable (value) becomes available in the scope of the caller. To use the value in the caller you can either use it directly in a statement or capture the value in a variable.

  2. Python return statement - GeeksforGeeks

    Dec 10, 2024 · Returns the boolean value of a. Let’s explore python return statement in detail: def function_name (parameters): # Function body. return value. When the return statement is executed, the function terminates and the specified value is returned to the caller. If no value is specified, the function returns None by default.

  3. python - How can I store a result of a function in a variable

    You can simply store the value of random.random() as you are doing to store in a, and after that you may return the value. import random def randombb(): a = random.random() print(a) return a x= randombb() print(x)

  4. The Python return Statement: Usage and Best Practices

    In this tutorial, you’ll learn that: You use return to send objects from your functions back to the caller code. You can use return to return one single value or multiple values separated by commas. You should try to keep your code readable and …

  5. python - How to retrieve a variable from a function ... - Stack Overflow

    Aug 4, 2022 · You'll need to either return the variable or use a global variable. Other answers have returned the variable, so here's an example using a global variable: global cart_items. cart_items = ["apple", "banana"] return cart_items. Like this: cart_items = ["apple", "banana"] return cart_items.

  6. Python Function Return Value - W3Schools

    def my_function(x): return 5 * x print(my_function(3)) print(my_function(5)) print(my_function(9))

  7. Returning a function from a function – Python - GeeksforGeeks

    Mar 19, 2025 · In Python, functions are first-class objects, allowing them to be assigned to variables, passed as arguments and returned from other functions. This enables higher-order functions, closures and dynamic behavior. Example: def …

  8. Python Return Value from Function: A Comprehensive Guide

    Jan 26, 2025 · In Python, we use the return statement to specify what value a function should return. For example: result = a + b. return result. In this code, the add_numbers function takes two arguments a and b, calculates their sum, and then returns the result using the return statement.

  9. Understanding How to Return a Value from a Function in Python

    To return a value from a function, use the return keyword followed by the value you want to return. It’s important to choose an appropriate data type for the return value based on your requirements.

  10. Return Value from Function - Python Examples

    Learn how to return values from functions in Python, using return statements to output results. Includes syntax, examples, and best practices.

  11. Some results have been removed
Refresh