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

    466 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. Calling a Python function with *args,**kwargs and optional / default ...

    Calling a Python function with *args,**kwargs and optional / default arguments Asked 13 years, 9 months ago Modified 4 years ago Viewed 75k times

  4. python - Argparse: Required arguments listed under "optional …

    See also the documentation: In general, the argparse module assumes that flags like -f and --bar indicate optional arguments, which can always be omitted at the command line. Note: Required …

  5. python - Argparse optional positional arguments? - Stack Overflow

    Optional arguments (e.g. --installdir /usr/bin/) One could argue that, in your case, you would be better off with an optional argument rather than a positional one.

  6. Python 3.10+: Optional [Type] or Type | None - Stack Overflow

    Oct 4, 2021 · None | t == typing.Optional[t] As @jonrsharpe comments, Union and Optional are not deprecated, so the Union and | syntax are acceptable. Łukasz Langa, a Python core developer, …

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

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

    Apr 9, 2021 · 9 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) …

  9. 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:

  10. how to make argument optional in python argparse

    This creates an optional argument that can be followed by zero or one command-line arguments. When parsing the command line, if the option string is encountered with no command-line argument …