Mastery 04 – Basic Types in Python

In Python there are 5 basic types: Integers, Floating-Point Numbers, Complex Numbers, Strings and Boolean.

Before I explain how to create and use the basic types in Python, note that Python is dynamic language unlike java and c# which are static languages. It means that variables need not be declared or defined. To create a variable, you just assign it a value and then start using it. Assignment is done with a single equals sign (=).

  1. Integers
    The int type in Python designates an integer number.
    num1 = 3

    --> print(num1 + 1)

  2. Floating-Point Numbers
    The float type in Python designates a floating-point number. float values are specified with a decimal point. Optionally, the character e or E followed by a positive or negative integer may be appended to specify scientific notation.

    num2 = 3.5
    num3 = 4e7

    --> print(num3 + 1)

  3. Complex Numbers
    The complex type in Python designates a complex number. Complex numbers are specified as <real part> + <imaginary part>j
    num4 = 2+3j

    --> print(num4 + 1 + 1j)

  4. Strings
    The str type in Python designates a string. A string is a sequence of characters that is delimited by single or double quotes.
    str = "Hello World"

    --> print(str + ", Tomer")
    Hello World, Tomer

  5. Boolean
    The bool type in Python designates a boolean. Variables of Boolean type may have one of two values: True or False.
    bool = True

    --> print(bool)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create your website at
Get started
%d bloggers like this: