Python
Keywords & operators
in programming
Stage 1 | level 2 – Keywords & operators PYTHON
The basics blocks of coding
Coding
Variables Datatypes Keywords Statements Operators
Stage 1 | level 2 – Keywords & operators PYTHON
KEYWORDS
Coding
Variables Datatypes Keywords Statements Operators
Every computer language has a number of keywords that you
will need to learn along with their meanings.
keywords are special reserved words that have specific
meanings and purposes and can’t be used for anything but
those specific purposes
there are thirty-five keywords (35) in Python.
Stage 1 | level 2 – Keywords & operators PYTHON
KEYWORDS
Coding
Variables Datatypes Keywords Statements Operators
False await else import pass
None break except in raise
True class finally is return
and continue for lambda try
as def from nonlocal while
assert del global not with
async elif if or yield
Stage 1 | level 2 – Keywords & operators PYTHON
Stage 1 | level 2 – Keywords & operators PYTHON
OPERATORS
Coding
Variables Datatypes Keywords Statements Operators
Operators are used to perform operations on variables and values
Python divides the operators in the following groups
Arithmetic Assignment Comparison Logical
operators operators operators operators
Identity Membership Bitwise
operators operators operators
Stage 1 | level 2 – Keywords & operators PYTHON
OPERATORS
Arithmetic operators
Used with numeric values to perform common mathematical operations
Operator Symbol Example Result
Addition + 10 + 20 30
Subtraction - 10 – 3 7
Multiplication * 10 * 20 200
Division / 10 / 3 3.3333333
Modulus % 10 % 3 1
Floor Division // 10 // 3 3
Exponentiation ** 10 ** 3 1000
Stage 1 | level 2 – Keywords & operators PYTHON
OPERATORS
Assignment Operators
Assignment operators are used to assign values to variables
Operator Example Same as
= x=5 x=5
+= x += 5 x=x+5
-= x -= 5 x=x-5
*= x *= 5 x=x*5
/= x /= 5 x=x/5
//= x //= 5 x = x // 5
**= x **= 5 x = x ** 5
Stage 1 | level 2 – Keywords & operators PYTHON
OPERATORS
Comparison Operators
Comparison operators are used to compare two values
Operator Name Example
== Equal x == 5
!= Not Equal x != 5
> Greater than x>5
< Less than x<5
>= Greater than or equal to x >= 5
<= less than or equal to x <= 5
Stage 1 | level 2 – Keywords & operators PYTHON
OPERATORS
Logical Operators
Logical operators are used to combine conditional statements
Operator Description Example
Returns True if both statements
and are true
x < 5 and x < 4
Returns True if one of the
or statements is true
x < 5 or x < 4
Reverse the result, returns False if
not the result is true
not(x < 5 and x < 10)
Stage 1 | level 2 – Keywords & operators PYTHON
OPERATORS
Identity Operators
Identity operators are used to compare the objects, not if they
are equal, but if they are actually the same object, with the
same memory location (works with collections mostly)
Operator Description Example
Returns True if both variables are
is the same object
x is y
Returns True if both variables are
is not not the same object
x is not y
Stage 1 | level 2 – Keywords & operators PYTHON
OPERATORS
Membership Operators
Membership operators are used to test if a sequence is
presented in an object
Operator Description Example
Returns True if a sequence with
in the specified value is present in x in y
the object
Returns True if a sequence with
not in the specified value is not present x not in y
in the object
Stage 1 | level 2 – Keywords & operators PYTHON
OPERATORS
Bitwise Operators
Bitwise operators are used to compare (binary) numbers
Operator Name Description
& AND Sets each bit to 1 if both bits are 1
| OR Sets each bit to 1 if one of two bits is 1
^ XOR Sets each bit to 1 if only one of two bits is 1
~ NOT Inverts all the bits
<< Zero fill left shift Shift left by pushing zeros in from the right and let
the leftmost bits fall off
>> Signed right shift Shift right by pushing copies of the leftmost bit in
from the left, and let the rightmost bits fall off
Stage 1 | level 2 – Keywords & operators PYTHON
Stage 1 | level 2 – Keywords & operators PYTHON
Assignment for
level 2 click here
Stage 1 | level 2 – Keywords & operators PYTHON
THE END
Stage 1 | level 2 – Keywords & operators PYTHON