What are keyword-only and positional-only parameters?
IntermediateConceptLanguage essentials & functions
Answer
Parameters after a bare * must be passed by keyword; parameters before / must be passed positionally.
def scale(deployment, replicas, /, *, namespace="default", dry_run=False): ...
scale("api", 3, dry_run=True) # ok
scale("api", 3, True) # TypeError
We make destructive flags like dry_run and force keyword-only so nobody can accidentally pass True in the wrong position.
More on Language essentials & functions
Why is Python the default scripting language in so many DevOps teams, and where would you not use it?BeginnerWhat is the difference between mutable and immutable types? Give examples.BeginnerWhat does assignment do in Python, and how do shallow and deep copies differ?BeginnerExplain the mutable default argument bug and how to fix it.IntermediateWhat is the difference between `==` and `is`?BeginnerWhat values are "falsy" in Python, and why does it matter in scripts?Beginner