Download Python
If you are just starting out, I recommend that you download Anaconda Integrated Development Environment. But, you can use any other IDE of choice. Latest installation instructions can be found from the official Anaconda website.
Spyder Application Overview
The Spyder application should present you with the following window. This consists of 2 commonly used parts:
- Code Editor that lets you create and edit existing Python source files
- IPython Console that gives access to Python Interactive mode
Using IPython Console
You can directly type Python code into this console and then press enter to execute the code fragment. Try typing 2*7
and press enter
key to get the result!
A Small Exercise
Example: To compute square root of a number, you can either raise it to a power (using **
operator) of 0.5 or use sqrt
function by importing the math
module.
In [3]: 10 ** 0.5
Out[3]: 3.1622776601683795In [4]: import math
In [5]: math.sqrt(10)
Out[5]: 3.1622776601683795
Exercise: Use the IPython Console to calculate the following:
In [6]: 2 + 2 * 10
In [7]: (2 + 2) * 10
In [8]: 25.5 ** 8In [9]: import math
In[10]: a = math.cos(30*math.pi/180)**2
In[11]: b = math.log(16, 2)
In[12]: a + b
Create, Save and Run .py file
- From Spyder’s File menu, select “New File” and type
print(“Hello World”)
.
- From Spyder’s File menu, select “Save As”, type name for the file and Save the file with .py extension.
- From Spyder’s Run menu, select “Run” (or use the green triangular Run button on toolbar or shortcut F5) and observe the result in the IPython Console.