All my python books and references I find on the web have simplistic
examples of the IF conditional. A few also provide examples of multiple
conditions that are ANDed; e.g.,
if cond1:
if cond2:
do_something.
However, I cannot find, nor create by trial-and-error, the syntax for
alternative conditions that are ORed; e.g.,
if cond1 OR if cond2:
do_something.
I've tried using the C syntax for OR (||) but python complained. I'm sure
there's a way to do this rather than using if cond1: elif cond2: both with
the same code to execute.
Please pass me a pointer so I can learn how to correctly write this.
Rich 6 1982 rs******@nospam .appl-ecosys.com wrote:
However, I cannot find, nor create by trial-and-error, the syntax for
alternative conditions that are ORed; e.g.,
if cond1 OR if cond2:
do_something.
if cond1 or cond2:
do_something() rs******@nospam .appl-ecosys.com writes:
if cond1:
if cond2:
do_something.
You can write:
if cond1 and cond2:
do_something
if cond1 OR if cond2:
do_something.
if cond1 or cond2:
do_something
I've tried using the C syntax for OR (||) but python complained. I'm sure
there's a way to do this rather than using if cond1: elif cond2: both with
the same code to execute.
Python uses the "and" and "or" keywords for && and ||.
En Thu, 08 Feb 2007 01:01:38 -0300, <rs******@nospa m.appl-ecosys.com>
escribió:
However, I cannot find, nor create by trial-and-error, the syntax for
alternative conditions that are ORed; e.g.,
if cond1 OR if cond2:
do_something.
Please pass me a pointer so I can learn how to correctly write this.
See the Python tutorial: http://docs.python.org/tut/node7.htm...00000000000000
Note that most (if not all) Python keywords are lowercase.
--
Gabriel Genellina
"Gabriel Genellina" <ga******@yahoo .com.arwrote:
Note that most (if not all) Python keywords are lowercase.
All keywords are lower case.
and del from not while
as elif global or with
assert else if pass yield
break except import print
class exec in raise
continue finally is return
def for lambda try
'None' is not entirely lowercase, and you cannot assign to it, but
technically it isn't a keyword. rs******@nospam .appl-ecosys.com wrote:
All my python books and references I find on the web have simplistic
examples of the IF conditional. A few also provide examples of multiple
conditions that are ANDed; e.g.,
if cond1:
if cond2:
do_something.
However, I cannot find, nor create by trial-and-error, the syntax for
alternative conditions that are ORed; e.g.,
if cond1 OR if cond2:
do_something.
I've tried using the C syntax for OR (||) but python complained. I'm sure
there's a way to do this rather than using if cond1: elif cond2: both with
the same code to execute.
Please pass me a pointer so I can learn how to correctly write this.
Rich
For lots of conditions:
import operator
reduce(operator .or_, list_of_conditi ons)
e.g.:
pyimport operator
pylist_of_condi tions = [
.... 'big' < 'small',
.... 'all' 'half',
.... 'five' 'one',
.... 'six' < 'seven'
.... ]
pylist_of_condi tions
[True, False, False, False]
pyreduce(operat or.or_, list_of_conditi ons)
True
James
On 2007-02-08, Paul Rubin <httpwrote:
rs******@nospam .appl-ecosys.com writes:
> if cond1: if cond2: do_something.
You can write:
if cond1 and cond2:
do_something
> if cond1 OR if cond2: do_something.
if cond1 or cond2:
do_something
> I've tried using the C syntax for OR (||) but python complained. I'm sure there's a way to do this rather than using if cond1: elif cond2: both with the same code to execute.
Python uses the "and" and "or" keywords for && and ||.
Allow me to thank all of you who responded with this one article. For
whatever reason, it did not occur to me to use the words 'and' and 'or.'
And, I did not see this in the tutorial or introduction ... which is my
fault.
So, I do thank all of you.
Rich This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Erlend Fuglum |
last post by:
Hi everyone,
I'm having some trouble sorting lists. I suspect this might have
something to do with locale settings and/or character
encoding/unicode.
Consider the following example, text containing norwegian special
characters æ, ø and å.
>>> liste =
|
by: Paul McGuire |
last post by:
There are a number of messages on the python-dev mail list that indicate
that Guido is looking for some concensus to come from this list as to what
*one* alternative syntax for decorators we would like him to consider in
place of the @ syntax that is currently in 2.4a2.
I think special thanks are due to:
- Anthony Baxter for his continuing efforts in this regard
- Steven Bethard for some of the clearest thinking and writing on this topic...
|
by: mheydman |
last post by:
I apologize if this has been asked before- I searched google but could
not find a concrete answer.
I recently inherited a database whose t-sql code is written in a format
that I find difficult to read (versus the format I have used for
years).
I have tested the queries below using the SQL Profiler, and both have
identical costs. Is there any advantage of one format over the other?
|
by: C# Learner |
last post by:
Why is C syntax so uneasy on the eye?
In its day, was it _really_ designed by snobby programmers to scare away
potential "n00bs"? If so, and after 50+ years of programming research,
why are programming languages still being designed with C's syntax?
These questions drive me insane. Every waking minute...
|
by: 43 |
last post by:
how come m$Office isn't written in .net?
how come Open Office isn't written in j2ee?
how come dbms systems aren't written in either?
how come browsers aren't written in either?
how come RealPlayer, MediaPlayer and all applications
that need speed are written in c++ ? (except for
| |
by: maruthir123 |
last post by:
Hi, I have a wchar_t pointer. Based on some conditions I assign string
literals to it and on some other conditions, I allocate memory and
assign it to this. Is there a way to find out while deleting if the
memory is deletable. I get an error if I try to delete this pointer
when Literals are assigned.
Thanks,
Maruthi
|
by: rogz |
last post by:
Hello,
i have a question about "design" issues in C.
In ACMqueue of february
(article here:
http://www.acmqueue.org/modules.php?name=Content&pa=showpage&pid=364
), KV says:
|
by: =?Utf-8?B?WFNsZXI=?= |
last post by:
I have some code that works fine, except for the fact that it has a lot of
embedded if statements. I don't think that this would be practice code, but I
wanted to tap into the knowledge of this group, and see what is the best way
to handle it. Basically, the if statements are used to check several
conditions of whether something is activated etc., and if it is, it outputs a
small piece of text and redirects the user to a new page. For each...
|
by: Patrick A |
last post by:
All,
I rely on nested IF statements with multiple conditions heavily, and
someone suggested recently writing the statements (and especially
reading them months later) would be much easier if I used Case
statements instead.
I've read several different examples of Case statements, but can't
quite figure out the syntax, or if they can be used when you need to
test for a pair of conditions, as I am doing below.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |