In [1]:
from __future__ import print_function

In [2]:
def show_names(first_name, last_name):
    print(
        'Your first name is %r. Your last name is %r.' %
        (first_name, last_name))

In [3]:
show_names('Even', 'Wager')

show_names(1234, 'wager')

# wager = 3.1415926
show_names(1234, wager)


Your first name is 'Even'. Your last name is 'Wager'.
Your first name is 1234. Your last name is 'wager'.
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-3-9dfc251c056c> in <module>()
      4 
      5 # wager = 3.1415926
----> 6 show_names(1234, wager)

NameError: name 'wager' is not defined

In [4]:
def goo(blah):
    print('do this')
    print('do that')

In [5]:
goo('lasdjkf')


do this
do that

In [6]:
goo()


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-6-085141544639> in <module>()
----> 1 goo()

TypeError: goo() takes exactly 1 argument (0 given)

In [7]:
goo(1, 2)


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-7-e8036428124b> in <module>()
----> 1 goo(1, 2)

TypeError: goo() takes exactly 1 argument (2 given)

In [8]:
def print_two(*args):
    # This is a terrible terrible example of *args. 
    print(type(args), repr(args))
    arg1, arg2 = args
    print("arg1: %r, arg2: %r" % (arg1, arg2))

In [9]:
print_two(1234, 'ehllo')


<type 'tuple'> (1234, 'ehllo')
arg1: 1234, arg2: 'ehllo'

In [10]:
type([])


Out[10]:
list

In [11]:
type(())


Out[11]:
tuple

In [12]:
def foo(*args):
    print(type(args), args)

In [13]:
foo(True, 'hello', 'world', 1234, 3.1415926, range(3))


<type 'tuple'> (True, 'hello', 'world', 1234, 3.1415926, [0, 1, 2])

In [14]:
for i in [0, 5, 9]:
    print('hello')
    print(i)
    print(i*i)
    print(i*i*i)
    print()


hello
0
0
0

hello
5
25
125

hello
9
81
729


In [15]:
def foo(*args):
    print(type(args), args)
    for arg in args:
        print('an argument is', arg)

In [16]:
foo(True, 'hello', 'world', 1234, 3.1415926, range(3))


<type 'tuple'> (True, 'hello', 'world', 1234, 3.1415926, [0, 1, 2])
an argument is True
an argument is hello
an argument is world
an argument is 1234
an argument is 3.1415926
an argument is [0, 1, 2]

In [17]:
def foo(*args):
    print(type(args), args)
    for i, arg in enumerate(args):
        print('Argument #', i, 'is', arg)

In [18]:
foo(True, 'hello', 'world', 1234, 3.1415926, range(3))


<type 'tuple'> (True, 'hello', 'world', 1234, 3.1415926, [0, 1, 2])
Argument # 0 is True
Argument # 1 is hello
Argument # 2 is world
Argument # 3 is 1234
Argument # 4 is 3.1415926
Argument # 5 is [0, 1, 2]

In [19]:
def foo(*args):
    print(type(args), args)
    for i, arg in enumerate(args):
        print('Argument #%s is %r' % (i, arg))

In [20]:
foo(True, 'hello', 'world', 1234, 3.1415926, range(3))


<type 'tuple'> (True, 'hello', 'world', 1234, 3.1415926, [0, 1, 2])
Argument #0 is True
Argument #1 is 'hello'
Argument #2 is 'world'
Argument #3 is 1234
Argument #4 is 3.1415926
Argument #5 is [0, 1, 2]