Beginner's Guide and Instructions to Programming in Python using the Spyder IDE

From PharmWiki
Jump to navigation Jump to search
  • This tutorial is based on the following website. No tutorial is perfect, so please feel free to email me. There are multiple ways to do things. Like anything, learning how to program takes practice. However, a big flaw in computer programming courses is that there is no practical aspect. Below is a summary in tabular format.
  1. Spyder IDE
  2. Repetitive Tasks with the IDE


  • This tutorial is based on this website. Each program builds on the other, so I recommend going in order. Because computer programs can escalate in size, I periodically write reviews that summarize the previous section and I try to keep the text of the summary to a single page. I made PDF versions of the programs. The best way to learn how to program is to hand type these programs and change them around. Therefore, I have made PDF versions of the programs in addition to the Python language versions.

Section #1-Comments, Print Statements, Variables and Concatenation

Section #1
# Topic Reference Command(s) Individual Files Explorer Console Output Variable Explorer Plots PDF Python Program Comments
1 Comments Link # Style #1 for line comments

''' Style #2 for block comments '''[1]

Comp010.png None None None 001-Comments.pdf I put this first because I put comments throughout

the programs, so that students understand.

2 Print Statements Link print("Some Text") or

print('Some Text')[2][3]

use of a backward slash \

None None 002-HelloWorld.pdf This is a classic beginning program Hello, World!.

You learn how to output characters in the console using

the print('output") Python command. You can put single

quotes within double quotes and vice-versa. The backward

slash (i.e., \) can be used to output invisible characters such

as tab

3 Variables Link variable types

casting: int(), str() and float()


None 003-Variables.pdf You learn about three different types of variables, namely string

(str), integer (int), and real numbers (float). You also learn how

to convert a variable using a process called casting.

4 Variables with


Similiar as previous, but will

demonstrate a computer concept

of concatenation.

Comp027.png Comp028.png Comp029.png None 004-Variables+Con.pdf You learn how to concatenate your output. Concatenate

essentially means to combine. You can combine using a plus

(i.e., +) or a comma.

5 Short Review of

Exercises 1-4

All the Above, but shorter
Comp031.png Comp032.png None 005-Short_Review.pdf Reviews the above in a shortened and less wordy format.

Section #2-Making decisions with the Python language using if-then-else statements and comparisons.

Section #2
# Topic Reference Command(s) Individuals Files Explorer Console Output Variable Explorer Plots PDF Python Program Comments
6 Code Sections,


Link if, elif, else Comp40.png Comp041.png Comp042.png None 006-If-then-else.pdf In this part, you will learn how code is put into sections. You will also learn how Python language

makes decisions through if, elif and else commands.

7 Code Sections,

Boolean, equivalent (equals to)

True, False, == Comp043.png Comp044.png Comp045.png None 007-Booleans.pdf In this part, you will learn about booleans. Basically, booleans are things like true or false, yes and

no. You will also learn about the Python equivalent of "equivalent to", which is double equals ==

8 Code Sections,

Comparison operators[4] (CO) and

Logical operators (LO)[5]


>,<,==, >=, <=


and, or not

Comp046.png Comp047.png Comp048.png None 008-Operators.pdf This part teaches you about comparison operators (i.e, comparing two values) and logical

operators. We will also talk more about booleans.

9 Short Review of Exercises 1-4 and 5--8. Comp049.png Comp050.png Comp051.png None 009-Short_Review.pdf This short review encompasses everything from exercises 1-4 and 6-8. The program

has concatenation, type() function, if-then-else statements, comparative operators and

logical operators.

Section #3-Arrays and Modules ⇒ Plotting with Matplotlib

  • I feel the best way to learn computer programming is to do something interesting and useful. You will need to know the above exercises 1-9 very well before you proceed. Computer programming builds on itself. If you prefer a slower introduction, I would recommend this tutorial. I have added a priority section to give you an idea of how you should prioritize learning Python. Some things you should know and others you can just be aware of it as you need it such as the Built-in Python Array Methods.
Section #3
# Topic Priority Reference More Info Command(s) Console Output Plot Output PDF Python Program Comments
10 Basic Built-In Math


know +,-,/,*,**

be aware of %

+,-,*,/,%,** Comp061.png None 010-Basic_Math.pdf With these exercises, you will learn basic math functions with Python.
11 List

(a.k.a. Array)

know it len()


Comp060.png None 011-Arrays.pdf This exercise teaches you the basic of Python arrays. To plot data, you need to

know arrays because they are the basis of all datasets.

12 List


know the append() method.

Link append()











Comp062.png None 012-Array_Methods.pdf

Only append()


Only append()


Set the Method2Try variable to the following programs:

1) append() method

2) copy() method

3) clear() method

4) count() method

5) extend() method

6) index() method

7) insert() method

8) pop() method

9) remove() method

10) reverse() method

11) sort() method

The 012-1-Append().py is only part of the to show how to separate it from the larger program.

13 List Functions

range() data type

tuple() data type

know len() and

range. Be aware

of the rest







Comp070.png None 013-Array_Functions.pdf Set the Function2Try variable to the following programs:

1) len(list1)- Gives the total length of the list.p>

2) max(list1)- Returns item from the list with max value.

3) min(list1)- Returns item from the list with min value.

4) list(tuple1)- Converts a tuple into list.

5) range(start,stop,step) - Make a list of numbers with certain parameters

14 Introduction to



know np.array() and

be aware of


Link Examples np.array()[6]


2D indexing

Comp074.png None 014-Introduction_to_Modules.pdf In this exercise, you will learn what modules are and then NumPy

module functions np.array() and np.matrix() that you need for the

next section.

15 Python Plotting Module:


Be aware of the

different plots available

in the Matplotlib


Link Examples plt.plot()[7][7]





Comp073.png Comp071.png 015-Matplotlib_Module.pdf Set the Plot2Try to the following programs:

1) Line Plot

2) Scatter Plot

3) Line and Point Plot

4) Dashed Line Plot

5) Line Plot with Axes Labels

6) Line Plot with Axes Labels and Title

7) Line Plot with Labels with Color

8) Line plot with Labels and Grid

Section #4-Loops and Loading Data

Section #4
# Topic Priority Reference More Info Command(s) Console Output Plot Output PDF Python Program Comments
16 Dictionaries, Arrays

and Loops

know it Link #1

Link #2

Link #3

Dictionary Data Type

for loops

while loops

Sec4-220227-1.png 016-Dictionaries_Arrays_Loops.pdf Set the Program2Try variable to the following programs

1) This program will print out the list of names using the for loop 2) List of names from a simple dictionary using a for loop

3) List of names from a complex dictionary using a for loop

4) Using a for loop with a range of numbers

5) Learn about a new type of loop called a "while loop"

6) Same as 5 except a different style of doing an Increment.

Nested Loop (Loop within a Loop)

7) Uses a nested loop for a two dimensional array

8) Uses a nested loop for a two dimensional numpy array

9) Uses a nested loop for a dictionary variable type. This has a similar output to #3

17 Reading, Parsing and Saving


be aware of







Sec2-220227-2.png 017-Reading_and_Parsing_Files.pdf Set the Program2Try variable to run the following programs

1) Display the file line by line using readlines() command.

2) Display a file all at once.

3) Same as 1, but use replace() function to remove hidden characters. Also, learn the strip() function that removes space at the beginning and end of the line.

4) Same as 2, but use replace function to remove hidden characters.

5) Similar to 4, learn how to split file into sentences using the split() function.

6) Similar to 5, but splits the file into words.

7) This is a more sophisticated program that makes a frequency. dictionary of text. Uses functions split(), lower(), strip() and replace().

8) Same as 7, but we are going to save the output using the csv module.

References and Notes

  1. You can block comments with three double quotes (i.e., ") or three single quotes (i.e., ').
  2. In Python 2.x versions, the command was print "Some Text" or print 'Some Text'
  3. Hello World is classically the first program that someone writes. See,_World!%22_program
  4. Operator in simple language is something that does "operates" on something else.
  6. 6.0 6.1 np is shorthand for numpy, when you import numpy as np.
  7. 7.0 7.1 7.2 7.3 7.4 7.5 plt is shorthand for matplotlib.pyplot