Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
99 views1 page

Python Operators and Booleans Cheat Sheet: by Via

This document provides a summary of Python operators and Boolean values. It lists the common arithmetic, assignment, comparison, logical, identity, membership, and bitwise operators in Python. It also defines what Boolean values of True and False represent and how logical operators like and, or, and not work in evaluating expressions that return True or False.

Uploaded by

pca_pca
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views1 page

Python Operators and Booleans Cheat Sheet: by Via

This document provides a summary of Python operators and Boolean values. It lists the common arithmetic, assignment, comparison, logical, identity, membership, and bitwise operators in Python. It also defines what Boolean values of True and False represent and how logical operators like and, or, and not work in evaluating expressions that return True or False.

Uploaded by

pca_pca
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Python Operators and Booleans Cheat Sheet

by Nouha_Thabet via cheatography.com/103894/cs/21322/

Python Arithmetic Operators Boolean Values Python Membership Operators

Addition 9 + 2 >> 11 In progra​mming you often need to know if in Returns True if a sequence with the

Subtra​ction 9 - 2 >> 7 an expression is True or False. specified value is present in the object
You can evaluate any expression in x in y
Multip​lic​ation 9 * 2 >> 18
Python, and get the answer.
not Returns True if a sequence with the
Division 9 / 2 >> 4.5
print(5 < 8) >>> True in specified value is not present in the
Modulus 9 % 2 >> 1
print(5 > 8) >>> False object
Expone​nti​ation 3 ** 2 >> 81
x not in y
Floor division 9 // 2 >> 4 Python Logical Operators

and Returns True if both statements are Python Bitwise Operators


Python Assignment Operators true & AND Sets each bit to 1 if both bits
Operator Example Same As x < 5 and x < 10 are 1
= x = 2 x = 2 or Returns True if one of the statements | OR Sets each bit to 1 if one of

+= x += 2 x = x + 2 is true two bits is 1

-= x -= 2 x = x - 2 x < 5 or x < 4 ^ XOR Sets each bit to 1 if only one


of two bits is 1
*= x *= 2 x = x * 2 not Reverse the result, returns False if
the result is true ~ NOT Inverts all the bits
/= x /= 2 x = x / 2
not(x < 5 and x < 10) << Zero Shift left by pushing zeros in
%= x %= 2 x = x % 2
fill left from the right and let the
//= x //= 2 x = x // 2 Python Identity Operators shift leftmost bits fall off
**= x **= 2 x = x ** 2 >> Signed Shift right by pushing copies
is Returns true if both variables are the
same object right of the leftmost bit in from the
Python Comparison Operators shift left, and let the rightmost
x is y
bits fall off
Equal x == y
is Returns true if both variables are not
Not equal x != y not the same object
Greater than x > y x is not y
Less than x < y

Greater than or equal to x >= y

Less than or equal to x <= y

By Nouha_Thabet Published 7th December, 2019. Sponsored by Readable.com


cheatography.com/nouha- Last updated 5th December, 2019. Measure your website readability!
thabet/ Page 1 of 1. https://readable.com

You might also like