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

    467 I have a Python function which takes several arguments. Some of these arguments could be omitted in some scenarios.

  2. How should I use the Optional type hint? - Stack Overflow

    Code that still supports older Python versions can still stick to using Optional. Optional[...] is a shorthand notation for Union[..., None], telling the type checker that either an object of the specific type is …

  3. python - Optional arguments without a default value - Stack Overflow

    Apr 9, 2021 · 10 The Python Documentation for parameters says the following: Parameter - A named entity in a function (or method) definition that specifies an argument (or in some cases, arguments) …

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

    Edit: I didn't know how default arguments worked in Python, but for the sake of this question, I will keep the examples above. In general it's much better to do the following:

  5. python - Is there a way to pass optional parameters to a function ...

    Dec 24, 2012 · The Python 2 documentation, 7.6. Function definitions gives you a couple of ways to detect whether a caller supplied an optional parameter. First, you can use special formal parameter …

  6. Optional Arguments in Python - Stack Overflow

    Sep 10, 2010 · Optional arguments in Python serve multiple purposes, but most often they are a mechanism to provide defaults where there are sensible and infrequently varied values exist.

  7. Is there a way to have optional arguments in a function in Python ...

    Mar 25, 2022 · I have defined a function in Python which takes some arguments and plots a graph. I would like to extend this so that if certain additional optional arguments are passed into the function …

  8. Passing an optional argument in a function - python

    Feb 8, 2016 · Note that in Python, the expression defining the default value for an optional argument is eval'd ony once when the def statement is executed (which is at first import for a top-level function), …

  9. python - How to type hint a Callable of a function with default ...

    Jul 14, 2021 · and optional arguments are one of those impossible things to express with a normal Callable. The / at the end of __call__ 's signature makes x a positional-only parameter, which allows …

  10. python - Optional command line arguments - Stack Overflow

    Nov 21, 2016 · 3 Suppose you want to run a python script test.py with or without one command line argument. examples: without argument- python ./test.py with argument- python ./test.py 'Martin'