Data Types

  • Text Type: str
  • Numeric Types: int, float, complex
  • Sequence Types: list, tuple, range
  • Mapping Type: dict
  • Set Types: set, frozenset
  • Boolean Type: bool
  • Binary Types: bytes, bytearray, memoryview

Type Conversion

You can convert object of one type to another For example:

  • float(3) converts integer 3 to float 3.0
  • int(3.9) converts float 3.9 to integer 3

Numbers

  • int represents integers, ex. 5
  • float represents real numbers, ex. 3.27
  • complex number has a “j” as the imaginary part, ex. 5j

Boolean

There are two Boolean values: True and False.

String

Strings store letters, special characters, spaces, digits, and enclose in quotation marks or single quotes "Hello" 'Hello'

List

A list can store a sequence of other objects [item1, item2, ..., itemN]

Python operators

Operators are used to perform operations on variables and values.

Python Arithmetic operators

OperationDescription
x + yAddition
x - ySubtraction
x * yMultipication
x / yDivision -> result is float
x // yDivision -> result is int
x % yRemainder of x / y for positive x, y
x ** yx to the power y

Python Comparison operators

They can be created by comparing values by using the rational operators

  • Equal: ==.
  • Not equal: !=
  • Greater than: >
  • Less than: <
  • Greater than or equal to: >=
  • Less than or equal to: <=

Python Logical operation

  • and
  • or
  • not

Python Membership Operators

We can use membership operators to test if a sequence is presented in an object:

  • in
  • not in For example
>>> x = 2
>>> y = [2,4]
>>> x in y
True