34 lines
964 B
Plaintext
34 lines
964 B
Plaintext
``++*++`` and ``++**++``, conventionally known as ``++*args++`` and ``++**kwargs++`` (although any names can be used), can be used in either a function definition or in a function call. In a function definition, they allow a variable number of arguments to be passed. In a function call, they simply obscure the actual values being used in the call.
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
[source,python]
|
|
----
|
|
my_arg_list = ("yellow", "green", 42)
|
|
my_arg_dictionary = {"first" : "Sam", "next": 4, "last": my_obj}
|
|
# many lines of code...
|
|
|
|
function_with_args(*my_arg_list) #Noncompliant
|
|
function_with_named_args(**my_arg_dictionary) #Noncompliant
|
|
----
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
[source,python]
|
|
----
|
|
function_with_args("yellow", "green", 42)
|
|
function_with_named_args(first = "Sam", next = 4, last = my_obj)
|
|
----
|
|
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::comments-and-links.adoc[]
|
|
endif::env-github,rspecator-view[]
|