@py3compat.format_doctest_out
    def __getitem__(self, item):

        if isinstance(item, slice):

            s,p,o=item.start,item.stop,item.step
            if s is None and p is None and o is None:
                return self.triples((s,p,o))
            elif s is None and p is None:
                return self.subject_predicates(o)
            elif s is None and o is None:
                return self.subject_objects(p)
            elif p is None and o is None:
                return self.predicate_objects(s)
            elif s is None:
                return self.subjects(p,o)
            elif p is None:
                return self.predicates(s,o)
            elif o is None:
                return self.objects(s,p)
            else:
                # all given
                return (s,p,o) in self

        elif isinstance(item, (Path,Node)):

            return self.predicate_objects(item)

        else:
            raise TypeError("You can only index a graph by a single rdflib term or path, or a slice of rdflib terms.")
A graph can be "sliced" as a shortcut for the triples method
dataset/ETHPy150Open RDFLib/rdflib/rdflib/graph.py/Graph.__getitem__