<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def path_segment(self, index, value=None, default=None):
 """ Return the path segment at the given index :param integer index: :param string value: the new segment value :param string default: the default value to return if no path segment exists with the given index """

        if value is not None:
            segments = list(self.path_segments())
            segments[index] = unicode_quote_path_segment(value)
            new_path = '/' + '/'.join(segments)
            if self._tuple.path.endswith('/'):
                new_path += '/'
            return URL._mutate(self, path=new_path)
        try:
            return self.path_segments()[index]
        except IndexError:
            return default