functions

Parameters

Sample

  • Advanced Parameter Handling For Functions

    def process(*params):
        for i in params:
            print i
    

    To pass a list or tuple to this function, use the * operator e.g:

    process(*(4,5,6,))
    
  • Why Python Rocks III: Parameter expansion

    def address(name, first_line, post_code):
        print '\nThe address is:\n%s\n%s\n%s\n' % (name, first_line, post_code)
    

    To pass a dictionary to this function, use the ** operator e.g:

    data = {
        'name': 'Patrick',
        'first_line': 'Moorview',
        'post_code': 'AB17 6DC',
    }
    
    address(**data)