Python Basics

The basics of Python.

Mathematical Operators

Operator
Syntax
Example

Addition

+

1+1=2

Subtraction

-

5-1=4

Multiplication

*

10*10=100

Division

/

10/2=5

Modulus

%

10%2=0

Exponent

**

5**2=25

Comparison Operators

Symbol
Syntax

Greater Than

>

Less Than

<

Equal To

==

Not Equal To

!=

Greater Than or Equal To

>=

Less Than or Equal To

<=

Data Types

  • String: combinations of characters like letters or symbols.

  • Integer: whole numbers.

  • Float: numbers with decimal points or fractions.

  • Boolean: data restricted to True or False.

  • List: series of different data types in a collection.

Logical Operators

Logical Operation
Operator
Example

Equivalence

==

if x == 5

Less Than

<

if x < 5

Less Than or Equal To

<=

if x <= 5

Greater Than

>

if x > 5

Greater Than or Equal To

>=

if x >= 5

Boolean Operators

Boolean Operation
Operator
Example

Both conditions must be true for the statement to be true.

AND

if x>=5 AND x<=100 True if x is between 5 and 100

Only one condition of the statement needs to be true.

OR

if x==1 OR x==10 True if x is 1 or 10

If a condition is the opposite of an argument.

NOT

if NOT y Returns True if y is False

Last updated