Python provides an if statement with the same semantics as languages like
C++ and Java, although with its own sparse syntax:
if expression1:
suite1
elif expression2:
suite2
else:
suite3
The first thing that stands out to programmers used to C++ or Java is that
there are no parentheses and no braces. The other thing to notice is the
colon: This is part of the syntax and is easy to forget when starting out. Colons
are used with else, elif, and in many other places to indicate that a block of
code (a suite in Python-speak) is to follow. As we would expect, there can be any
number.
Group
Operators
Description
Comparison
<, <=, ==, !=, >=, >
The <> operator is also permitted as a synonym
for != but is deprecated
Identity
is, is not
These are used to determine if two object references refer to the same underlying object
Membership
in, not in These are used on lists, dictionaries, and strings
Logical
not, and,or
Both and and or short-circuit; the bit-wise equivalents are:~ (not), & (and), | (or), and^ (xor)
Comments
Post a Comment