What is unpacking, including star-unpacking?
IntermediateConceptLanguage essentials & functions
Answer
host, port = "db.internal:5432".split(":")
first, *rest = sys.argv[1:]
*_, last = path.parts
merged = {**defaults, **overrides} # later wins
cmd = ["kubectl", *base_args, "apply", "-f", path]
Unpacking raises ValueError: too many values to unpack (or "not enough") when counts do not match, which is a useful early failure when parsing key=value lines. Use .split(":", 1) or .partition(":") when the value itself may contain the separator.
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