Book Image

NumPy: Beginner's Guide

By : Ivan Idris
Book Image

NumPy: Beginner's Guide

By: Ivan Idris

Overview of this book

Table of Contents (21 chapters)
NumPy Beginner's Guide Third Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
NumPy Functions' References
Index

Time for action – using Python as a calculator


We can use Python as a calculator as follows:

  1. In a Python shell, add 2 and 2 as follows:

    >>> 2 + 2
    4
    
  2. Multiply 2 and 2 as follows:

    >>> 2 * 2
    4
    
  3. Divide 2 and 2 as follows:

    >>> 2/2
    1
    
  4. If you have programmed before, you probably know that dividing is a bit tricky since there are different types of dividing. For a calculator, the result is usually adequate, but the following division may not be what you were expecting:

    >>> 3/2
    1
    

    We will discuss what this result is about in several later chapters of this book. Take the cube of 2 as follows:

    >>> 2 ** 3
    8
    

What just happened?

We used the Python shell as a calculator and performed addition, multiplication, division, and exponentiation.