def rgb2hex(r, g, b):
    """
    Convert rgb color to hex format.

    >>> rgb2hex(129, 154, 70)
    '#819a46'
    >>> rgb2hex(-10, 256, -1)
    Traceback (most recent call last):
    ...
    AssertionError: (r, g, b) value must within range 0 ~ 255.
    """
    assert (0, 0, 0) <= (r, g, b) <= (255, 255, 255
        ), '(r, g, b) value must within range 0 ~ 255.'
    hex = '#{:02x}{:02x}{:02x}'.format(r, g, b)
    return hex
