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.
    create:
    num1 = 3

    use:
    --> print(num1 + 1)
    4


  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.

    create:
    num2 = 3.5
    num3 = 4e7


    use:
    --> print(num3 + 1)
    40000001.0


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

    use:
    --> print(num4 + 1 + 1j)
    (3+4j)


  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.
    create:
    str = "Hello World"

    use:
    --> 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.
    create:
    bool = True

    use:
    --> print(bool)
    True
Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 WordPress.com
Get started
%d bloggers like this: