Skip to content

Commit 4645017

Browse files
committed
Initial commit
1 parent 5e71790 commit 4645017

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+176199
-0
lines changed

Diff for: .travis.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
sudo: false
2+
language: python
3+
4+
install:
5+
- pip install jupyter
6+
- pip install tox
7+
- pip install nbval
8+
- pip install pytest
9+
10+
11+
stages:
12+
- test
13+
14+
jobs:
15+
include:
16+
- python: 3.5
17+
env: TOXENV=py35
18+
- python: 3.6
19+
env: TOXENV=py36
20+
21+
script:
22+
- tox

Diff for: LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 jerry-git
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Diff for: README.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Teach and learn Python 3
2+
3+
[![Build Status](https://travis-ci.org/jerry-git/learn-python3.svg?branch=master)](https://travis-ci.org/jerry-git/learn-python3)
4+
5+
## Introduction
6+
7+
This repository contains a collection of materials for teaching/learning Python 3 (3.5+).
8+
9+
#### Requirements
10+
* Have Python 3.5 or newer installed. You can check the version by typing `python3 --version` in your command line. You can download the latest Python version from [here](https://www.python.org/downloads/).
11+
* Have [Jupyter Notebook installed](http://jupyter.readthedocs.io/en/latest/install.html).
12+
13+
If you can not access Python and/or Jupyter Notebook on your machine, you can still follow the web based materials. However, you should be able to use Jupyter Notebook in order to complete the exercises.
14+
15+
#### Usage
16+
17+
1. Clone or download the repository.
18+
2. Run `jupyter notebook` command in your command line in the repository directory.
19+
3. Jupyter Notebook session will open in your browser and you can start navigating through the materials.
20+
21+
22+
## Beginner
23+
1. [Strings](http://htmlpreview.github.com/?https://github.com/jerry-git/learn-python3/blob/master/notebooks/beginner/html/strings.html) [[notebook]](https://github.com/jerry-git/learn-python3/blob/master/notebooks/beginner/strings.ipynb) [[exercise]](https://github.com/jerry-git/learn-python3/blob/master/notebooks/beginner/exercises/strings_exercise.ipynb)
24+
1. [Numbers](http://htmlpreview.github.com/?https://github.com/jerry-git/learn-python3/blob/master/notebooks/beginner/html/numbers.html) [[notebook]](https://github.com/jerry-git/learn-python3/blob/master/notebooks/beginner/numbers.ipynb) [[exercise]](https://github.com/jerry-git/learn-python3/blob/master/notebooks/beginner/exercises/numbers_exercise.ipynb)
25+
1. [Conditionals](http://htmlpreview.github.com/?https://github.com/jerry-git/learn-python3/blob/master/notebooks/beginner/html/conditionals.html) [[notebook]](https://github.com/jerry-git/learn-python3/blob/master/notebooks/beginner/conditionals.ipynb) [[exercise]](https://github.com/jerry-git/learn-python3/blob/master/notebooks/beginner/exercises/conditionals_exercise.ipynb)
26+
1. [Lists](http://htmlpreview.github.com/?https://github.com/jerry-git/learn-python3/blob/master/notebooks/beginner/html/lists.html) [[notebook]](https://github.com/jerry-git/learn-python3/blob/master/notebooks/beginner/lists.ipynb) [[exercise]](https://github.com/jerry-git/learn-python3/blob/master/notebooks/beginner/exercises/lists_exercise.ipynb)
27+
1. [Dictionaries](http://htmlpreview.github.com/?https://github.com/jerry-git/learn-python3/blob/master/notebooks/beginner/html/dictionaries.html) [[notebook]](https://github.com/jerry-git/learn-python3/blob/master/notebooks/beginner/dictionaries.ipynb) [[exercise]](https://github.com/jerry-git/learn-python3/blob/master/notebooks/beginner/exercises/dictionaries_exercise.ipynb)
28+
1. [For loops](http://htmlpreview.github.com/?https://github.com/jerry-git/learn-python3/blob/master/notebooks/beginner/html/for_loops.html) [[notebook]](https://github.com/jerry-git/learn-python3/blob/master/notebooks/beginner/for_loops.ipynb) [[exercise]](https://github.com/jerry-git/learn-python3/blob/master/notebooks/beginner/exercises/for_loops_exercise.ipynb)
29+
1. [Functions](http://htmlpreview.github.com/?https://github.com/jerry-git/learn-python3/blob/master/notebooks/beginner/html/functions.html) [[notebook]](https://github.com/jerry-git/learn-python3/blob/master/notebooks/beginner/functions.ipynb) [[exercise]](https://github.com/jerry-git/learn-python3/blob/master/notebooks/beginner/exercises/functions_exercise.ipynb)
30+
1. [Testing with pytest - part 1](http://htmlpreview.github.com/?https://github.com/jerry-git/learn-python3/blob/master/notebooks/beginner/html/testing1.html) [[notebook]](https://github.com/jerry-git/learn-python3/blob/master/notebooks/beginner/testing1.ipynb)
31+
1. RECAP EXERCISE 1
32+
1. [File I\O](http://htmlpreview.github.com/?https://github.com/jerry-git/learn-python3/blob/master/notebooks/beginner/html/file_io.html) [[notebook]](https://github.com/jerry-git/learn-python3/blob/master/notebooks/beginner/file_io.ipynb)
33+
1. [Classes](http://htmlpreview.github.com/?https://github.com/jerry-git/learn-python3/blob/master/notebooks/beginner/html/classes.html) [[notebook]](https://github.com/jerry-git/learn-python3/blob/master/notebooks/beginner/classes.ipynb) [[exercise]](https://github.com/jerry-git/learn-python3/blob/master/notebooks/beginner/exercises/classes_exercise.ipynb)
34+
1. [Exceptions](http://htmlpreview.github.com/?https://github.com/jerry-git/learn-python3/blob/master/notebooks/beginner/html/exceptions.html) [[notebook]](https://github.com/jerry-git/learn-python3/blob/master/notebooks/beginner/exceptions.ipynb)
35+
1. Project structure
36+
1. [Debugging](http://htmlpreview.github.com/?https://github.com/jerry-git/learn-python3/blob/master/notebooks/beginner/html/debugging.html) [[notebook]](https://github.com/jerry-git/learn-python3/blob/master/notebooks/beginner/debugging.ipynb) [[exercise]](https://github.com/jerry-git/learn-python3/blob/master/notebooks/beginner/exercises/debugging_exercise.ipynb)
37+
1. [Goodies of the Standard Library](http://htmlpreview.github.com/?https://github.com/jerry-git/learn-python3/blob/master/notebooks/beginner/html/std_lib.html) [[notebook]](https://github.com/jerry-git/learn-python3/blob/master/notebooks/beginner/std_lib.ipynb)
38+
1. [Testing with pytest - part 2](http://htmlpreview.github.com/?https://github.com/jerry-git/learn-python3/blob/master/notebooks/beginner/html/testing2.html) [[notebook]](https://github.com/jerry-git/learn-python3/blob/master/notebooks/beginner/testing2.ipynb)
39+
1. RECAP EXERCISE 2

Diff for: notebooks/beginner/classes.ipynb

+167
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# [Classes](https://docs.python.org/3/tutorial/classes.html#a-first-look-at-classes)"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": null,
13+
"metadata": {},
14+
"outputs": [],
15+
"source": [
16+
"class MyFirstClass:\n",
17+
" def __init__(self, name):\n",
18+
" self.name = name\n",
19+
"\n",
20+
" def greet(self):\n",
21+
" print('Hello {}!'.format(self.name))"
22+
]
23+
},
24+
{
25+
"cell_type": "code",
26+
"execution_count": null,
27+
"metadata": {},
28+
"outputs": [],
29+
"source": [
30+
"my_instance = MyFirstClass('John Doe')\n",
31+
"print('my_intance: {}'.format(my_instance))\n",
32+
"print('type: {}'.format(type(my_instance)))\n",
33+
"print('my_instance.name: {}'.format(my_instance.name))"
34+
]
35+
},
36+
{
37+
"cell_type": "markdown",
38+
"metadata": {},
39+
"source": [
40+
"## Methods\n",
41+
"The functions inside classes are called methods. They are used similarly as functions. "
42+
]
43+
},
44+
{
45+
"cell_type": "code",
46+
"execution_count": null,
47+
"metadata": {},
48+
"outputs": [],
49+
"source": [
50+
"alice = MyFirstClass(name='Alice')\n",
51+
"alice.greet()"
52+
]
53+
},
54+
{
55+
"cell_type": "markdown",
56+
"metadata": {},
57+
"source": [
58+
"### `__init__()`\n",
59+
"`__init__()` is a special method that is used for initialising instances of the class. It's called when you create an instance of the class. "
60+
]
61+
},
62+
{
63+
"cell_type": "code",
64+
"execution_count": null,
65+
"metadata": {},
66+
"outputs": [],
67+
"source": [
68+
"class Example:\n",
69+
" def __init__(self):\n",
70+
" print('Now we are inside __init__')\n",
71+
" \n",
72+
"print('creating instance of Example')\n",
73+
"example = Example()\n",
74+
"print('instance created')"
75+
]
76+
},
77+
{
78+
"cell_type": "markdown",
79+
"metadata": {},
80+
"source": [
81+
"`__init__()` is typically used for initialising instance variables of your class. These can be listed as arguments after `self`. To be able to access these instance variables later during your instance's lifetime, you have to save them into `self`. `self` is the first argument of the methods of your class and it's your access to the instance variables and other methods. "
82+
]
83+
},
84+
{
85+
"cell_type": "code",
86+
"execution_count": null,
87+
"metadata": {},
88+
"outputs": [],
89+
"source": [
90+
"class Example:\n",
91+
" def __init__(self, var1, var2):\n",
92+
" self.first_var = var1\n",
93+
" self.second_var = var2\n",
94+
" \n",
95+
" def print_variables(self):\n",
96+
" print('{} {}'.format(self.first_var, self.second_var))\n",
97+
" \n",
98+
"e = Example('abc', 123)\n",
99+
"e.print_variables()\n",
100+
" "
101+
]
102+
},
103+
{
104+
"cell_type": "markdown",
105+
"metadata": {},
106+
"source": [
107+
"## Class variables vs instance variables\n",
108+
"Class variables are shared between all the instances of that class whereas instance variables can hold different values between different instances of that class."
109+
]
110+
},
111+
{
112+
"cell_type": "code",
113+
"execution_count": null,
114+
"metadata": {},
115+
"outputs": [],
116+
"source": [
117+
"class Example:\n",
118+
" # These are class variables\n",
119+
" name = 'Example class'\n",
120+
" description = 'Just an example of a simple class'\n",
121+
"\n",
122+
" def __init__(self, var1):\n",
123+
" # This is an instance variable\n",
124+
" self.instance_variable = var1\n",
125+
"\n",
126+
" def show_info(self):\n",
127+
" info = 'instance_variable: {}, name: {}, description: {}'.format(\n",
128+
" self.instance_variable, Example.name, Example.description)\n",
129+
" print(info)\n",
130+
"\n",
131+
"\n",
132+
"inst1 = Example('foo')\n",
133+
"inst2 = Example('bar')\n",
134+
"\n",
135+
"# name and description have identical values between instances\n",
136+
"assert inst1.name == inst2.name == Example.name\n",
137+
"assert inst1.description == inst2.description == Example.description\n",
138+
"\n",
139+
"# If you change the value of a class variable, it's changed across all instances\n",
140+
"Example.name = 'Modified name'\n",
141+
"inst1.show_info()\n",
142+
"inst2.show_info()"
143+
]
144+
}
145+
],
146+
"metadata": {
147+
"kernelspec": {
148+
"display_name": "Python 3",
149+
"language": "python",
150+
"name": "python3"
151+
},
152+
"language_info": {
153+
"codemirror_mode": {
154+
"name": "ipython",
155+
"version": 3
156+
},
157+
"file_extension": ".py",
158+
"mimetype": "text/x-python",
159+
"name": "python",
160+
"nbconvert_exporter": "python",
161+
"pygments_lexer": "ipython3",
162+
"version": "3.5.4"
163+
}
164+
},
165+
"nbformat": 4,
166+
"nbformat_minor": 2
167+
}

0 commit comments

Comments
 (0)