Print a few usage examples on stdout.

def demo(nums=[]):
    "Print a few usage examples on stdout."

    nums = nums or [3, 1, 4, 1, 5, 9, 2, 6]
    fmt = lambda num: '{0:g}'.format(num) if isinstance(num, (float, int)) else 'None'
    nums1 = list(map(fmt, nums))

    if __name__ == '__main__':
        prog = sys.argv[0]
    else:
        prog = 'sparklines'

    result = []


    result.append('Usage examples (command-line and programmatic use):')
    result.append('')

    result.append('- Standard one-line sparkline')
    result.append('{0!s} {1!s}'.format(prog, ' '.join(nums1)))
    result.append('>>> print(sparklines([{0!s}])[0])'.format(', '.join(nums1)))
    result.append(sparklines(nums)[0])
    result.append('')

    result.append('- Multi-line sparkline (n=2)')
    result.append('{0!s} -n 2 {1!s}'.format(prog, ' '.join(nums1)))
    result.append('>>> for line in sparklines([{0!s}], num_lines=2): print(line)'.format(', '.join(nums1)))
    for line in sparklines(nums, num_lines=2):
        result.append(line)
    result.append('')

    result.append('- Multi-line sparkline (n=3)')
    result.append('{0!s} -n 3 {1!s}'.format(prog, ' '.join(nums1)))
    result.append('>>> for line in sparklines([{0!s}], num_lines=3): print(line)'.format(', '.join(nums1)))
    for line in sparklines(nums, num_lines=3):
        result.append(line)
    result.append('')

    nums = nums + [None] + list(reversed(nums[:]))
    result.append('- Standard one-line sparkline with gap')
    result.append('{0!s} {1!s}'.format(prog, ' '.join(map(str, nums))))
    result.append('>>> print(sparklines([{0!s}])[0])'.format(', '.join(map(str, nums))))
    result.append(sparklines(nums)[0])
    return '\n'.join(result) + '\n'