Loeng 1: Python, sissejuhatus programmeerimisse Pythonis, Pythoni installeerimine, konsool, Jupyter, minu esimene programm, lihtne aritmeetika, sõne (string), funktsioon print
¶
Lisa 1: Integreeritud arenduskeskkonna Jupyter kasutamise juhend (Integrated Development Environment (IDE) Jupyter)¶
Jupyteri koodirakud töötavad kahes režiimis:
- Command mode - Hall/mitteaktiivne (JupyteLab) või sinine (Jupyter Notebook) koodirakk.
- Edit mode - Sinine (JupyteLab) või roheline (Jupyter Notebook) koodirakk.
Press Enter or double click to enter the edit mode. Press Esc to enter the command mode. Use arrows to move between cells.
While in edit mode:
Ctrl + Enter interpret the code.
Shift + Enter interpret the code + moves to the next cell.
Alt + Enter interpret the code + creates new cell + moves to the created cell.
TAB shows methods and attributes of an object.
Shift + TAB shows the DocString info.
While in command mode:
A to insert a new cell above the current cell.
B to insert a new cell below.
M to change the current cell to Markdown.
Y to change it back to code.
D + D (press the key twice) to delete the current cell.
Split cells:
Ctrl + Shift + - will split the current cell into two from where your cursor is.
Merge cells:
Shift + M to merge multiple cells.
Select multiple cells:
Shift + Down or Shift + J selects the next sell in a downwards direction.
Shift + Up or Shift + K select cells in an upwards direction.
Once cells are selected, you can then delete, copy, cut, paste or run them as a batch. This is helpful when you need to move parts of a notebook.
Other:
Esc + F to find and replace on your code but not the outputs.
Esc + O to toggle cell output.
While cell is interpreting (calculating) it displays In [*]
.
Help:
For help type into a cell:
help()
or help(<objectname>)
Info on a specific object:
?objectname
or objectname?
For general contextual help (DocStrings) while typing use:
Ctrl + I
Shutting down kernels:
Closing Jupyter server and kernels in the console:
Ctrl + C
Or use the Jupyter IDE graphical interface.
Lisa 2: Jupyteri koodirakk ja Markdown, HTML ning $\LaTeX$¶
Allolev info pole seotud Pythoni programmeerimiskeelega. Allolev materjal ei lähe eksamisse. Loe edasi kui sind huvitab kuidas loengutes kasutatavad loengu materjalid (.html failid) ja praktikumides kasutatavad töölehed (.ipynb failid) töötavad ja on loodud. Lae kursuse kodulehelt alla käesolev veebilehe loomiseks kasutatud Jupyteri tööleht (.ipynb fail) ning uuri selle koodirakkudes olevat lähtekoodi. Eelmainitud õppematerjalide loomiseks kasutati kolme erinevat skriptimiskeelt: Markdown, HTML ja $\LaTeX$.
- Markdown projekti koduleht: https://daringfireball.net/projects/markdown/
- HTML keele arendajad ja haldajad: https://whatwg.org/
- $\LaTeX$ projekti koduleht: https://www.latex-project.org/
Jupyteri töölehe koodirakku saab muuta Markdown'ks vajutades M koodiraku command reziimis.
Teksti lisamine töölehte¶
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Linkide lisamine: https://www.youtube.com/
Markdowni režiimis olev Jupyteri koodirakk toetab HTML'i keelt. HTML tag'de lisamine: CTRL + Z
Valemid sisesta kasutades $\LaTeX{}$'i skriptimiskeele süntaksi. Tekstirea sees olev valem $\frac{\partial u}{\partial x} = \sin y$. Eraldi real olevad valemid sisesta nii:
$$\frac{\rm d}{{\rm d}x}\left[\left(1-x^2\right) \frac{{\rm d}P_n(x)}{{\rm d}x}\right] + n(n+1) P_n(x) = 0.$$Tabelid¶
Option | Description |
---|---|
data | path to data files to supply the data that will be passed into templates. |
engine | engine to be used for processing templates. Handlebars is the default. |
ext | extension to be used for dest files. |
Paremale, vasakule ja keskele joondatud veergude sisu:
Option | Description | Description2 |
---|---|---|
data | 12 | a |
engine | 5555 | b |
ext | 78 xyz | c 123 |
Laisk inimene saab ka hakkama:
Markdown | Less | Pretty |
---|---|---|
Still | renders |
nicely |
1 | 2 | 3 |
Lähtekood teksti osana¶
See on Pythoni koodi süntaksi näide plt.plot(x,y)
tekstirea sees.
Koodi lõik:
import matplotlib.pyplot as plt
plt.plot(x,y)
plt.show()
Teeme ilusamaks:
import matplotlib.pyplot as plt
for x in range(12):
print('Hello')
plt.plot(x,y)
plt.show()
Joonis 1. Näidisjoonis mis kujutab arvutit. |
Jooniste ja piltide lisamine¶
Paiguta joonise või pildi fail töökausta ning viita sellele kasutades HTML tagi <img>
. Tulemus on nähtav Joonisel 1.