About 150,000 results
Open links in new tab
  1. python - How do I define a function with optional arguments?

    See the Python documentation for an excellent summary; the various other answers to the question make use of most of these variations. Since you always have parameters a, b, c in …

  2. How can I specify the function type in my type hints?

    Jun 15, 2016 · How can I specify the type hint of a variable as a function type? There is no typing.Function, and I could not find anything in the relevant PEP, PEP 483.

  3. python - When to create a nested function inside a function and …

    Feb 16, 2021 · If you are making this make_multiplier as part of some library/API, using Structure 1 "hides" this f function and makes it a bit clearer and more readable to clients/users of the …

  4. Define a method outside of class definition? - Stack Overflow

    May 26, 2018 · You can define a function outside of a class and then add it. However, there is a subtle difference in assigning the function to the class or to the instance object.

  5. How to specify multiple types using type-hints - Stack Overflow

    I have a function in python that can either return a bool or a list. Is there a way to specify the types using type hints? For example, is this the correct way to do it? def foo(id) -> list or b...

  6. python - Is nested function a good approach when required by …

    Jan 29, 2011 · Let's say that a function A is required only by function B, should A be defined inside B? Simple example. Two methods, one called from another: def method_a(arg): …

  7. How can I define a mathematical function in SymPy?

    1 Have a look at SymPy: How to define variables for functions, integrals and polynomials. You can define it according to these two ways: a Python function with def as described above a Python …

  8. python - How can I use a global variable in a function? - Stack …

    Jul 11, 2016 · In Python, the module is the natural place for global data: Each module has its own private symbol table, which is used as the global symbol table by all functions defined in the …

  9. python - Creating functions (or lambdas) in a loop (or …

    The original code already uses closures - and the closures are only ever created behind the scenes by Python. It's just that each function created in the loop in the OP, generates its …

  10. How do I call a function from another .py file? [duplicate]

    function(a, b) Note that file is one of Python's core modules, so I suggest you change the filename of file.py to something else. Note that if you're trying to import functions from a.py to a file …