string help
Steven D'Aprano
steve at REMOVETHIScyber.com.au
Tue Nov 15 05:58:36 EST 2005
On Tue, 15 Nov 2005 09:35:00 +0000, Simon Brunning wrote:
> On 14/11/05, john boy <xray_alpha_charlie at yahoo.com> wrote:
>> using the following program:
>>
>> prefixes = "JKLMNOPQ"
>> suffix = "ack"
>> for letter in prefixes:
>> print letter + suffix
>> if prefixes == "O" or "Q"
>
> Here you need:
>
> if prefixes == "O" or prefixes == "Q"
Or you could do this:
if prefixes in ("O", "Q"):
or even:
if prefixes in "OQ":
The first example compares prefixes with "O" and then "Q", the second
looks to see if prefixes is a substring of "OQ". In this case, they will
both have the same effect.
--
Steven.
More information about the Python-list
mailing list