def part_encode(part):
    """Encode a part of a JSON pointer.

    >>> part_encode("foo")
    'foo'
    >>> part_encode("~foo")
    '~0foo'
    >>> part_encode("foo~")
    'foo~0'
    >>> part_encode("/foo")
    '~1foo'
    >>> part_encode("foo/")
    'foo~1'
    >>> part_encode("f/o~o")
    'f~1o~0o'
    >>> part_encode("~0")
    '~00'
    >>> part_encode("~1")
    '~01'
    >>> part_encode(0)
    '0'
    """
    return str(part).replace("~", "~0").replace("/", "~1")