Skip to content

Commit e76f2b0

Browse files
authored
Merge pull request #19 from teresa-mcgee/dev
Adding Dev Branch, Merging updates from 2023
2 parents 467aaa9 + 1dd5703 commit e76f2b0

File tree

11 files changed

+2779
-89
lines changed

11 files changed

+2779
-89
lines changed

.DS_Store

8 KB
Binary file not shown.
Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
{
2+
"cells": [
3+
{
4+
"attachments": {},
5+
"cell_type": "markdown",
6+
"metadata": {},
7+
"source": [
8+
"[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/How-to-Learn-to-Code/python-class/blob/master/Lesson_1_Basics/Lesson_1_Student_Version.ipynb)"
9+
]
10+
},
11+
{
12+
"attachments": {},
13+
"cell_type": "markdown",
14+
"metadata": {},
15+
"source": [
16+
"# Lesson 0 - Basic Introduction to Programming in Python"
17+
]
18+
},
19+
{
20+
"attachments": {},
21+
"cell_type": "markdown",
22+
"metadata": {},
23+
"source": [
24+
"### Learning objectives\n",
25+
"\n",
26+
"Students will gain an introduction to programming in python, working in interactive notebooks, and learning how to leverage outside resources for coding help. Moreoever students will gain a basic understanding of variables, data types, and working with simple expressions for comparison and computation.\n",
27+
"\n",
28+
"* [Introduction to Programming](#program)\n",
29+
"* [Introduction to Jupyter and Google Colab](#jupyter)\n",
30+
"* [Rigor and Reproducibility in your code](#rigor-reproducibility)\n"
31+
]
32+
},
33+
{
34+
"attachments": {},
35+
"cell_type": "markdown",
36+
"metadata": {},
37+
"source": [
38+
"#### Basic Introduction to Programming in Python <a id='program'></a>"
39+
]
40+
},
41+
{
42+
"attachments": {},
43+
"cell_type": "markdown",
44+
"metadata": {},
45+
"source": [
46+
"Python is a general purpose programming language that is widely used in scientific computing, image analysis, machine learning etc. It allows you to specify a set of instructions, written as a script or a program, to execute some task of interest. \n",
47+
"\n",
48+
"* Have any of you used a script before? What did you do to run it? What was the purpose of the script? Did it aid in reproducibility? Was it quicker to run or modify than calculating things individually by hand? \n",
49+
"\n",
50+
"The purpose of this series of python workshops is not to give you an extensive in depth overview of everything you can do in python. However, we do aim to give you all the skills and terminology necessary to **learn** how to learn to code in python. Google, [stack overflow](https://stackoverflow.com/), and [github issues](https://github.com/)) are invaluable tools you can use to your advantage for (1) gaining coding help and (2) learning how to write code from reading code."
51+
]
52+
},
53+
{
54+
"attachments": {},
55+
"cell_type": "markdown",
56+
"metadata": {},
57+
"source": [
58+
"#### Introduction to Jupyter Notebooks and Google Colab <a id='jupyter'></a>"
59+
]
60+
},
61+
{
62+
"attachments": {},
63+
"cell_type": "markdown",
64+
"metadata": {},
65+
"source": [
66+
"We will be using the online server [Google Collab](https://colab.research.google.com) for learning python. This server creates an isolated \"environment\" for you to work in. Using your Google account (or you will have to create one) open up Google Collab in your web browser. Start a \"new notebook\" to create a new python file.\n",
67+
"\n",
68+
"There are many types of files that you can use for Python coding. The most important for you now are :\n",
69+
"* .py : This is a python script file. All things in this file have to be python code. You would use this file for a complete analysis.\n",
70+
"* .ipynb : This is a Jupyter Notebook file. Jupyter is a user interface to seemlessly code in python. This worksheet was made in a Jupyter Notebook!"
71+
]
72+
},
73+
{
74+
"attachments": {},
75+
"cell_type": "markdown",
76+
"metadata": {},
77+
"source": [
78+
"\"The Jupyter Notebook is an incredibly powerful tool for interactively developing and presenting data science projects. A notebook integrates code and its output into a single document that combines visualizations, narrative text, mathematical equations, and other rich media. The intuitive workflow promotes iterative and rapid development, making notebooks an increasingly popular choice at the heart of contemporary data science, analysis, and increasingly science at large. \" - [dataquest](https://www.dataquest.io/blog/jupyter-notebook-tutorial/)\n",
79+
"\n",
80+
"All of our lessons will be presented in Jupyter notebooks due to their interactive nature (.ipynb file extension). They consist of two main attributes, a `kernel` and `cells`. \n",
81+
"* A `kernel` interprets and executes the code. Here we are using the kernel for python; however, you can specify a kernel for another language like R. \n",
82+
"* A `cell` is a container for either text or code to be executed. \n",
83+
"\n",
84+
"To run the python code in a cell, you just hit shift + enter. Try it with the code below."
85+
]
86+
},
87+
{
88+
"cell_type": "code",
89+
"execution_count": null,
90+
"metadata": {},
91+
"outputs": [],
92+
"source": [
93+
"print('hello world')"
94+
]
95+
},
96+
{
97+
"attachments": {},
98+
"cell_type": "markdown",
99+
"metadata": {},
100+
"source": [
101+
"#### Rigor and Reproducibility In Your Code <a id='rigor-reproducibility'></a>"
102+
]
103+
},
104+
{
105+
"attachments": {},
106+
"cell_type": "markdown",
107+
"metadata": {},
108+
"source": [
109+
"Similar to an author writing, a programmer will adopt a style of coding. This can be as small as how many new lines you have between code lines, to the way you comment your code, and how you name your variables. Matching a standard style of code will help make your code more readable and more reproducible. If you continue your coding journey, we recommend the [PEPS Style Guide for Python](https://peps.python.org/pep-0008). Go ahead and look through this resource, but focus on the Commenting, Code Lay-out, and Naming Convention sections. "
110+
]
111+
},
112+
{
113+
"attachments": {},
114+
"cell_type": "markdown",
115+
"metadata": {},
116+
"source": [
117+
"##### Commenting Your Code\n"
118+
]
119+
},
120+
{
121+
"attachments": {},
122+
"cell_type": "markdown",
123+
"metadata": {},
124+
"source": [
125+
"One of the most important things you can do to learn and to help other programmers read your code, is using meaningfull comments. Comments will begin with a # sign within a code chunk. You can have an inline comment, to provide information for a speicifc like of code, or a block of comments to describe a section. You want these comments to be concise but informative. \n",
126+
"\n",
127+
"At the begining of every file, use a block of comments to outline the python file youre making. This will also be good practice for documentation for any public code you publish... Like this: "
128+
]
129+
},
130+
{
131+
"cell_type": "code",
132+
"execution_count": null,
133+
"metadata": {},
134+
"outputs": [],
135+
"source": [
136+
"# File name : lesson_0_Student_version\n",
137+
"# Goal : This script is a practice for the How to Learn to Code class. It is introducing reproducible code using Jupyter notebook and coding styles. \n",
138+
"# Input : NA\n",
139+
"# Output : NA\n",
140+
"# Libraries : NA\n",
141+
"# Required : Google account\n"
142+
]
143+
},
144+
{
145+
"attachments": {},
146+
"cell_type": "markdown",
147+
"metadata": {},
148+
"source": [
149+
"Examples of input would be the datasets you need, other files that are used in this script, ect. You also may have figures as outputs, or processed data. List all of these at the top of your code, so that you can find the information quickly when you return. If youre using a notebook file, like you will be in this class, feel free to add this in a \"Markdown\" chunk instead."
150+
]
151+
},
152+
{
153+
"attachments": {},
154+
"cell_type": "markdown",
155+
"metadata": {},
156+
"source": [
157+
"Your inline comments should be added to describe an important line of code. Look at the formatting below:"
158+
]
159+
},
160+
{
161+
"cell_type": "code",
162+
"execution_count": null,
163+
"metadata": {},
164+
"outputs": [],
165+
"source": [
166+
"i = 2\n",
167+
"\n",
168+
"# Good commenting style :\n",
169+
"\n",
170+
"if i & (i-1) == 0: # True if i is 0 or a power of 2.\n",
171+
"\n",
172+
"# Bad commenting style : \n",
173+
"\n",
174+
"if i & (i-1) == 0: #checking i"
175+
]
176+
},
177+
{
178+
"attachments": {},
179+
"cell_type": "markdown",
180+
"metadata": {},
181+
"source": [
182+
"##### Naming Conventions"
183+
]
184+
},
185+
{
186+
"attachments": {},
187+
"cell_type": "markdown",
188+
"metadata": {},
189+
"source": [
190+
"When you are naming somehting in your code, like a variable here, it is important to follow a few rules:\n",
191+
"* always start the name with a letter (no numbers or special characters)\n",
192+
"* never start a name with an underscore (this is reserved for official Python variables nad functions)\n",
193+
"* avoid long variable names \n",
194+
"* use a specific naming style (we will use \"snake case\" which is all lowercase, and has an underscore seperating words)"
195+
]
196+
},
197+
{
198+
"cell_type": "code",
199+
"execution_count": null,
200+
"metadata": {},
201+
"outputs": [],
202+
"source": [
203+
"# Good naming style : \n",
204+
"\n",
205+
"apples = ['granny_smith','machintosh','golden_delicious']\n",
206+
"granny_smith = 'green'\n",
207+
"machintosh = 'red'\n",
208+
"golden_delicious = 'yellow'\n",
209+
"\n",
210+
"# Bad naming style :\n",
211+
"\n",
212+
"list_ofApples=['gs','MACIN','_golden_']\n",
213+
"gs= 'green'\n",
214+
"MACIN =\"Red'\n",
215+
"\n",
216+
"\n",
217+
"_Golden='y'"
218+
]
219+
},
220+
{
221+
"attachments": {},
222+
"cell_type": "markdown",
223+
"metadata": {},
224+
"source": [
225+
"Finally, when naming your files, find a format that works well for you, but follow these few rules :\n",
226+
"* if you start your files with a number, and you expect to have more than 10 (or more than 100) add a zero to the begining of the file name. Computers will treat the number in the name as part of the alphabet, so if you don't do this, the computer orders them incorrectly\n",
227+
" * WRONG : 1_facs_data.fcs, 10_facs_data.fcs, 11_facs_data.fcs ... 2_facs data.fcs\n",
228+
" * RIGHT : 01_facs_data.fcs, 02_facs_data.fcs, ..... 10_facs_data.fcs\n",
229+
" * RIGHT : 001_facs_data.fcs, 02_facs_data.fcs, ..... 010_facs_data.fcs ... 100_facs_data.fcs\n",
230+
"\n",
231+
"* never have a space in your file name \n",
232+
" * WRONG : facs data.fcs\n",
233+
" * RIGHT : facs_data.fcs\n",
234+
"\n",
235+
"* For a project, always name your files similar to eachother\n",
236+
" * WRONG : 01_facs_data.fcs, facsdata2.fsc, 3_facs_data.fsc, mouse4_facs_data_.fsc"
237+
]
238+
}
239+
],
240+
"metadata": {
241+
"interpreter": {
242+
"hash": "c4d4cf0f866ef5d608adbb3b8114bb30b4107b67947e423d500be3fa738ca8f5"
243+
},
244+
"kernelspec": {
245+
"display_name": "Python 3",
246+
"language": "python",
247+
"name": "python3"
248+
},
249+
"language_info": {
250+
"codemirror_mode": {
251+
"name": "ipython",
252+
"version": 3
253+
},
254+
"file_extension": ".py",
255+
"mimetype": "text/x-python",
256+
"name": "python",
257+
"nbconvert_exporter": "python",
258+
"pygments_lexer": "ipython3",
259+
"version": "3.8.3"
260+
}
261+
},
262+
"nbformat": 4,
263+
"nbformat_minor": 4
264+
}

0 commit comments

Comments
 (0)