@py3compat.format_doctest_out
    def __getitem__(self, item):
        """
        A graph can be "sliced" as a shortcut for the triples method
        The python slice syntax is (ab)used for specifying triples.
        A generator over matches is returned,
        the returned tuples include only the parts not given

        >>> import rdflib
        >>> g = rdflib.Graph()
        >>> g.add((rdflib.URIRef('urn:bob'), rdflib.RDFS.label, rdflib.Literal('Bob')))

        >>> list(g[rdflib.URIRef('urn:bob')]) # all triples about bob
        [(rdflib.term.URIRef(%(u)s'http://www.w3.org/2000/01/rdf-schema#label'), rdflib.term.Literal(%(u)s'Bob'))]

        >>> list(g[:rdflib.RDFS.label]) # all label triples
        [(rdflib.term.URIRef(%(u)s'urn:bob'), rdflib.term.Literal(%(u)s'Bob'))]

        >>> list(g[::rdflib.Literal('Bob')]) # all triples with bob as object
        [(rdflib.term.URIRef(%(u)s'urn:bob'), rdflib.term.URIRef(%(u)s'http://www.w3.org/2000/01/rdf-schema#label'))]

        Combined with SPARQL paths, more complex queries can be
        written concisely:

        Name of all Bobs friends:

        g[bob : FOAF.knows/FOAF.name ]

        Some label for Bob:

        g[bob : DC.title|FOAF.name|RDFS.label]

        All friends and friends of friends of Bob

        g[bob : FOAF.knows * '+']

        etc.

        .. versionadded:: 4.0

        """

        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) is not 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.")
dataset/ETHPy150Open RDFLib/rdflib/rdflib/graph.py/Graph.__getitem__/operator `in` -> `is not`