Beginner's Guide and Instructions to Programming in Python using the JupyterLab IDE
- 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.
Tutorial
- 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
# | Topic | Reference | Command(s) | Individual Files Explorer | Console Output | Variable Explorer | Plots | Python Program | Comments | |
---|---|---|---|---|---|---|---|---|---|---|
1 | Comments | Link | # Style #1 for line comments
''' Style #2 for block comments '''[1] |
![]() |
None | None | None | 001-Comments.pdf | 001-Comments.py | I put this first because I put comments throughout
the programs, so that students understand. |
2 | Print Statements | Link | print("Some Text") or
use of a backward slash \ |
frameless|100x100px | left|frameless|100x100px | None | None | 002-HelloWorld.pdf | 002-HelloWorld.py | 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() type() |
None | 003-Variables.pdf | 003-Variables.py | 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
Concatenation |
Similiar as previous, but will
demonstrate a computer concept of concatenation. |
![]() |
![]() |
![]() |
None | 004-Variables+Con.pdf | 004-Variables+Con.py | 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 | ![]() |
![]() |
None | 005-Short_Review.pdf | 005-Short_Review.py | 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.
# | Topic | Reference | Command(s) | Individuals Files Explorer | Console Output | Variable Explorer | Plots | Python Program | Comments | |
---|---|---|---|---|---|---|---|---|---|---|
6 | Code Sections,
If-then-else-statements |
Link | if, elif, else | ![]() |
![]() |
![]() |
None | 006-If-then-else.pdf | 006-If-then-else.py | 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, == | ![]() |
![]() |
![]() |
None | 007-Booleans.pdf | 007-Booleans.py | 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] |
CO:
>,<,==, >=, <= LO: and, or not |
![]() |
![]() |
None | 008-Operators.pdf | 008-Operators.py | 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. | ![]() |
![]() |
![]() |
None | 009-Short_Review.pdf | 009-Short_Review.py | 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.
# | Topic | Priority | Reference | More Info | Command(s) | Console Output | Plot Output | Python Program | Comments | |
---|---|---|---|---|---|---|---|---|---|---|
10 | Basic Built-In Math
Functions |
know +,-,/,*,**
be aware of % |
+,-,*,/,%,** | ![]() |
None | 010-Basic_Math.pdf | 010-Basic_Math.py | With these exercises, you will learn basic math functions with Python. | ||
11 | List
(a.k.a. Array) |
know it | len()
indexing |
![]() |
None | 011-Arrays.pdf | 011-Arrays.py | 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
Methods |
know the append() method.
|
Link | append()
copy() clear() count() extend() index() insert() pop() remove() reverse() sort() |
![]() |
None | 012-Array_Methods.pdf
Only append() |
012-Array_Methods.py
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 012-Array_Methods.py 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 |
len()
min() max() list() tuple() range() |
![]() |
None | 013-Array_Functions.pdf | 013-Array_Functions.py | 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
Modules- |
know np.array() and
be aware of np.matrix(). |
Link | Examples | np.array()[6]
np.matrix()[6] 2D indexing |
![]() |
None | 014-Introduction_to_Modules.pdf | 014-Introduction_to_Modules.py | 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:
Matplotlib |
Be aware of the
different plots available in the Matplotlib module. |
Link | Examples | plt.plot()[7]plt.show()[7]
plt.xlabel()[7] plt.ylabel()[7] plt.title()[7] plt.grid()[7] |
![]() |
![]() |
015-Matplotlib_Module.pdf | 015-Matplotlib_Module.py | 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
# | Topic | Priority | Reference | More Info | Command(s) | Console Output | Plot Output | Python Program | Comments | |
---|---|---|---|---|---|---|---|---|---|---|
16 | Dictionaries, Arrays
and Loops |
know it | Link #1 | Dictionary Data Type
for loops while loops |
![]() |
016-Dictionaries_Arrays_Loops.pdf | 016-Dictionaries_Arrays_Loops.py | 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
Files |
be aware of
it |
split()
lower() strip() replace() open() |
![]() |
017-Reading_and_Parsing_Files.pdf | 017-Reading_and_Parsing_Files.py | 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
- ↑ You can block comments with three double quotes (i.e., ") or three single quotes (i.e., ').
- ↑ In Python 2.x versions, the command was print "Some Text" or print 'Some Text'
- ↑ Hello World is classically the first program that someone writes. See https://en.wikipedia.org/wiki/%22Hello,_World!%22_program
- ↑ Operator in simple language is something that does "operates" on something else.
- ↑ https://vegibit.com/logical-and-comparison-operators-in-python/
- ↑ 6.0 6.1 np is shorthand for numpy, when you import numpy as np.
- ↑ 7.0 7.1 7.2 7.3 7.4 7.5 plt is shorthand for matplotlib.pyplot