About 5,550,000 results
Open links in new tab
  1. How to Use a Variable from Another Function in Python

    May 31, 2024 · Use a Variable from Another Function Using Class Attributes. In this example, we use a class to encapsulate the variable as an attribute. This allows different methods within the …

  2. python - How do I pass variables across functions? - Stack Overflow

    I want to pass values (as variables) between different functions. For example, I assign values to a list in one function, then I want to use that list in another function: list = [] def defineALis...

  3. How do you carry variables from multiple functions to another - Python

    Feb 3, 2023 · Call each function, in turn, and have said function return some value. Then use the returned values when you call Magic(d, m) , having done def Magic(DAY, Month): for example. …

  4. Multiple return - Python Tutorial

    In the most simple case you can return a single variable: Call the function with complexfunction (2,3) and its output can be used or saved. But what if you have multiple variables in a function …

  5. Python Guide: Managing Persistent Variables Across Function Calls

    Nov 21, 2024 · Learn how to maintain persistent variables across function calls in Python using global variables, class attributes, decorators, and closures. Includes practical examples and …

  6. Call a Variable from Another Function in Python - Online …

    Learn how to call a variable from another function in Python with this comprehensive guide. Understand the concept and see examples for better comprehension.

  7. python - How to use a variable defined inside one function from another

    The simplest option is to use a global variable. Then create a function that gets the current word. Notice that to read global variables inside a function, you do not need to use the global keyword.

  8. How to use a Variable from another Function in Python

    Apr 11, 2024 · There are multiple ways that enable you to use a variable from another function in Python: You can return the variable from the first function and store the return value in the …

  9. Using Global Variables in Python Functions: Best Practices and ...

    May 1, 2025 · Conclusion. Using global variables in Python functions is sometimes necessary—but it should be done with caution. Understanding Python’s variable scope is …

  10. Returning Multiple Values in Python - GeeksforGeeks

    May 2, 2023 · One alternative approach for returning multiple values from a function in Python is to use the yield keyword in a generator function. A generator function is a special type of …

Refresh