Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
executable file
·
75 lines (52 loc) · 1.21 KB

File metadata and controls

executable file
·
75 lines (52 loc) · 1.21 KB
Copy raw file
Download raw file
Outline
Edit and raw actions

Boolean expression

Examples in Python 3

"""
Basic comparisons
"""
# Equals
x, y = 4, 4
print(x, "equals", y, "=", x == y)

x, y = "five", "five"
print(x, "equals", y, "=", x == y)


# Not equal
x, y = 4, 5
print(x, "does not equal", y, "=", x != y)

# Larger than
x, y = 10, 2
print(x, "is larger than", y, "=", x > y)

# Smaller than
x, y = 10, 2
print(x, "is smaller than", y, "=", x < y)

# Larger than or equal to
x, y = 10, 10
print(x, "is larger or equal to", y, "=", x >= y)

# Smaller than or equal to
x, y = 2, 10
print(x, "is smaller or equal to", y, "=", x <= y)


"""
Is and is not
"""
# Is - compares identity, not value
x = y = 4
print(x, "is", y, "=", x is y)

x = 4, 2
y = 4, 2
print(x, "is", y, "=", x is y)

print(x, "is not", y, "=", x is not y)


"""
In
"""
x = [1,2,3]
y = 2
print(y, "is in", x, "=", y in x)

print(y, "is not in", x, "=", y not in x)

Reference and read more

Comparisons - reference

Comparisons - library

Revision history

2014-07-16 (sylvanas) PA1 First try.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.