Skip to content

Commit 672c6f7

Browse files
committed
Merge pull request yasoob#59 from Kwpolska/patch-1
Fix *args and **kwargs code for Python 3 and PEP 8
2 parents 5d20a01 + dc42b03 commit 672c6f7

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

args_and_kwargs.rst

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ an example to help you get a clear idea:
2222
.. code:: python
2323
2424
def test_var_args(f_arg, *argv):
25-
print "first normal arg:", f_arg
25+
print("first normal arg:", f_arg)
2626
for arg in argv:
27-
print "another arg through *argv :", arg
27+
print("another arg through *argv:", arg)
2828
29-
test_var_args('yasoob','python','eggs','test')
29+
test_var_args('yasoob', 'python', 'eggs', 'test')
3030
3131
This produces the following result:
3232

3333
.. code:: python
3434
3535
first normal arg: yasoob
36-
another arg through *argv : python
37-
another arg through *argv : eggs
38-
another arg through *argv : test
36+
another arg through *argv: python
37+
another arg through *argv: eggs
38+
another arg through *argv: test
3939
4040
I hope this cleared away any confusion that you had. So now let's talk
4141
about \*\*kwargs
@@ -50,9 +50,8 @@ arguments** in a function. Here is an example to get you going with it:
5050
.. code:: python
5151
5252
def greet_me(**kwargs):
53-
if kwargs is not None:
54-
for key, value in kwargs.iteritems():
55-
print "%s == %s" %(key, value)
53+
for key, value in kwargs.items():
54+
print("{0} == {1}".format(key, value))
5655
5756
>>> greet_me(name="yasoob")
5857
name == yasoob
@@ -71,9 +70,9 @@ Just consider that you have this little function:
7170
.. code:: python
7271
7372
def test_args_kwargs(arg1, arg2, arg3):
74-
print "arg1:", arg1
75-
print "arg2:", arg2
76-
print "arg3:", arg3
73+
print("arg1:", arg1)
74+
print("arg2:", arg2)
75+
print("arg3:", arg3)
7776
7877
Now you can use \*args or \*\*kwargs to pass arguments to this little
7978
function. Here's how to do it:

0 commit comments

Comments
 (0)