Assigning "None" to a function that requires transfer parameters (Python)

Question:

I’m struggling at assigning "None" values to all parameter of a function.

for i in range(18):
    sx.set_attribute(v{i}=None)

The attributes I want to fill with "None" are v0 -> v18
I’m only looking for the right syntax.
If you know a better way to assign "None" values to vars that do not contain values, present it too.

Asked By: mathandlogic

||

Answers:

You can first create a dictionary with function parameters(v0 -> v18) as keys and value as None. Then use ** to unpack the dictionary as function arguments.

sx.set_attribute(**{f"v{i}": None for i in range(18)})
Answered By: Abdul Niyas P M
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.