Python keywords

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • gtb

    #1

    Python keywords


    Have done some searching but have not found a place where I can look
    up python keywords. I was looking at a script that contained the
    following line:

    assert self.getRespons eCode() in (200, 304, 302)

    I can infer the usage here but previously I had thought that "in" was
    only used with '"for". I looked thru 'the Python Reference Manual and
    found "in" is a keyword but in skimming thru I found it only with
    "for". The reference manual seems good but seems not to be setup for
    searching. Or maybe I just missed something.

    Thanks,

    gtb

  • Larry Bates

    #2
    Re: Python keywords

    gtb wrote:
    Have done some searching but have not found a place where I can look
    up python keywords. I was looking at a script that contained the
    following line:
    >
    assert self.getRespons eCode() in (200, 304, 302)
    >
    I can infer the usage here but previously I had thought that "in" was
    only used with '"for". I looked thru 'the Python Reference Manual and
    found "in" is a keyword but in skimming thru I found it only with
    "for". The reference manual seems good but seems not to be setup for
    searching. Or maybe I just missed something.
    >
    Thanks,
    >
    gtb
    >


    in keyword is a general one and can be used for many objects.

    x in 'xyz'

    y in ['a','b','c','y' ,'z'']

    z in ('a','b','c','y ','z']

    key in {'key1':1, 'key2': 2}

    The in you see with a for isn't associated with the for loop
    but rather the sequence you are iterating over

    for i in range(10):

    -Larry

    Comment

    • Marc 'BlackJack' Rintsch

      #3
      Re: Python keywords

      In <1177599386.204 340.65680@r35g2 000prh.googlegr oups.com>, gtb wrote:
      Have done some searching but have not found a place where I can look
      up python keywords. I was looking at a script that contained the
      following line:
      >
      assert self.getRespons eCode() in (200, 304, 302)
      >
      I can infer the usage here but previously I had thought that "in" was
      only used with '"for". I looked thru 'the Python Reference Manual and
      found "in" is a keyword but in skimming thru I found it only with
      "for". The reference manual seems good but seems not to be setup for
      searching. Or maybe I just missed something.
      If you look in the library reference index you'll find a link to the
      `Sequence Types`_ section where it is mentioned as an operator that tests
      if some object "contains" another. And the reference manual has an index
      entry called `in operator` which leads to the page Comparisons_, telling
      how to overwrite the behaviour in your own classes.

      ... _Sequence Types: http://docs.python.org/lib/typesseq.html
      ... _Comparisons: http://docs.python.org/ref/comparisons.html

      Ciao,
      Marc 'BlackJack' Rintsch

      Comment

      • gtb

        #4
        Re: Python keywords

        On Apr 26, 10:16 am, Larry Bates <larry.ba...@we bsafe.comwrote:
        gtb wrote:
        Have done some searching but have not found a place where I can look
        up python keywords. I was looking at a script that contained the
        following line:
        >
        assert self.getRespons eCode() in (200, 304, 302)
        >
        I can infer the usage here but previously I had thought that "in" was
        only used with '"for". I looked thru 'the Python Reference Manual and
        found "in" is a keyword but in skimming thru I found it only with
        "for". The reference manual seems good but seems not to be setup for
        searching. Or maybe I just missed something.
        >
        Thanks,
        >
        gtb
        >

        >
        in keyword is a general one and can be used for many objects.
        >
        x in 'xyz'
        >
        y in ['a','b','c','y' ,'z'']
        >
        z in ('a','b','c','y ','z']
        >
        key in {'key1':1, 'key2': 2}
        >
        The in you see with a for isn't associated with the for loop
        but rather the sequence you are iterating over
        >
        for i in range(10):
        >
        -Larry
        Thanks Larry. I saw that page you referenced above and that is how I
        knew it was a keyword. But I still have found nodocumentation that
        supports the examples you provided.


        Thanks again,

        john

        Comment

        • gtb

          #5
          Re: Python keywords


          Thanks Marc.

          Comment

          • gtb

            #6
            Re: Python keywords

            On Apr 26, 1:59 pm, "Hamilton, William " <wham...@enterg y.comwrote:
            -----Original Message-----
            From: python-list-bounces+whamil1 =entergy....@py thon.org
            [mailto:python-
            list-bounces+whamil1 =entergy....@py thon.org] On Behalf Of gtb
            Sent: Thursday, April 26, 2007 1:50 PM
            To: python-l...@python.org
            Subject: Re: Python keywords
            >
            On Apr 26, 10:16 am, Larry Bates <larry.ba...@we bsafe.comwrote:
            >
            in keyword is a general one and can be used for many objects.
            >
            x in 'xyz'
            >
            y in ['a','b','c','y' ,'z'']
            >
            z in ('a','b','c','y ','z']
            >
            key in {'key1':1, 'key2': 2}
            >
            The in you see with a for isn't associated with the for loop
            but rather the sequence you are iterating over
            >
            for i in range(10):
            >
            -Larry
            >
            Thanks Larry. I saw that page you referenced above and that is how I
            knew it was a keyword. But I still have found nodocumentation that
            supports the examples you provided.
            >

            >
            This information is 2 clicks away from any page in the reference: click
            the index link, then scroll down to the link to "in operator".
            >
            ---
            -Bill Hamilton
            Thanks, Bill.

            I clicked there before and decided I must be experiencing an indexing
            error or such due to using firefox instead of IE when I didn't see "in
            operator" at the top of the page.

            Best Regards,

            john

            Comment

            • Alex Martelli

              #7
              Re: Python keywords

              gtb <goodTweetieBir d@hotmail.comwr ote:
              Have done some searching but have not found a place where I can look
              up python keywords.
              >>import keyword
              >>keyword.kwlis t
              ['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del',
              'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global',
              'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print',
              'raise', 'return', 'try', 'while', 'with', 'yield']

              call help(kw) from an interpreter prompt for any one of these values for
              more information. E.g.,
              >>help('and')
              will give you section 5.1 (Boolean operations), all the way to
              help('yield') giving 6.8 (The yield statement). Some of the keywords
              have no specific info, e.g. help('as') will not be very informative:-).


              Alex

              Comment

              Working...