About 154,000 results
Open links in new tab
  1. 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.

  2. python - How do I define a function with optional arguments?

    0 A Python function can take in some arguments, take this for example, def add(x,y): return x+ y # calling this will require only x and y add(2,3) # 5 If we want to add as many arguments as we …

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

    Jul 11, 2016 · In Python, variables that are only referenced inside a function are implicitly global. If a variable is assigned a new value anywhere within the function’s body, it’s assumed to be a …

  4. 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): …

  5. Python: How to create a function? e.g. f(x) = ax^2 - Stack Overflow

    Python (and most other computer languages) don't do algebra, which is what you'll need if you want symbolic output like this. But you could have a function f(a,x) which returns the result for …

  6. 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 …

  7. python - How do I add default parameters to functions when …

    If I have a function like this: def foo (name, opts= {}): pass And I want to add type hints to the parameters, how do I do it? The way I assumed gives me a syntax error: def foo (name: str, …

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

    Feb 26, 2012 · 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.

  9. How to know function return type and argument types?

    202 While I am aware of the duck-typing concept of Python, I sometimes struggle with the type of arguments of functions, or the type of the return value of the function. Now, if I wrote the …

  10. python - How do I forward-declare a function to avoid …

    In python the statement globals()[function_name]() is the same as foo() if function_name = 'foo' for the reasons discussed above, since python must lookup each function before calling it. If one …