SPECIFYING DEFAULT VALUES IN A FUNCTION
Listing 2.13 shows the content of DefaultValues.py, which illustrates how to specify default values in a function.
Listing 2.13: DefaultValues.py
def numberFunc(a, b=10):
 print (a,b)
def stringFunc(a, b='xyz'):
 print (a,b)
def collectionFunc(a, b=None):
 if(b is None):
  print('No value assigned to b')
numberFunc(3)
stringFunc('one')
collectionFunc([1,2,3])
Listing 2.13 defines three functions, followed by an invocation of each of those functions. The functions numberFunc() and stringFunc() print a list contain the values of their two parameters, and collectionFunc() displays a message if the second parameter is None. The output from Listing 2.13 is here:
(3, 10)
('one', 'xyz')
No value assigned to b
Returning Multiple Values From a Function
This task is accomplished by the code in Listing 2.14, which shows the content of MultipleValues.py.
Listing 2.14...