Python keywords

G

gtb

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.getResponseCode() 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
 
L

Larry Bates

gtb said:
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.getResponseCode() 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
http://docs.python.org/ref/keywords.html

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
 
M

Marc 'BlackJack' Rintsch

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.getResponseCode() 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
 
G

gtb

gtb said:
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.getResponseCode() 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.

gtb

http://docs.python.org/ref/keywords.html

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
 
G

gtb

-----Original Message-----
From: [email protected] [mailto:python-
[email protected]] On Behalf Of gtb
Sent: Thursday, April 26, 2007 1:50 PM
To: (e-mail address removed)
Subject: Re: Python keywords
http://docs.python.org/ref/keywords.html
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.

http://docs.python.org/ref/comparisons.html#l2h-438

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".

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
 
A

Alex Martelli

gtb said:
Have done some searching but have not found a place where I can look
up python keywords.
['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.,

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top