Professional Documents
Culture Documents
Forelesning 1: Innledning Til Programmering I Python. Programmeringsmiljøer For Python: Spyder Og Jupyter Notebook
Forelesning 1: Innledning Til Programmering I Python. Programmeringsmiljøer For Python: Spyder Og Jupyter Notebook
Forelesning 1: Innledning Til Programmering I Python. Programmeringsmiljøer For Python: Spyder Og Jupyter Notebook
#: inline comments
- Difference in the big and small letters when it comes to the variable names.
- No difference in using the space in the command.
- F5: kjører koden i hele filen
- Omregne fra .txt til .py: in the browsing box to save the file, write .py and the whole name in
anførselstegn “”.
- To open a file with the given path in Python, Ctr O, paste the link in the Filename box
- Necessary to install a package and import it in the code when using it (e.g numpy,..)
- If a code is too long, then we can put the mouse right after the comma and enter -> the first
letter of the remaining arguments will go in vertical line with the previous arguments in the
code.
- In order to just see the results of a specific line, bold that line and F9, then you can see the
corresponding result in console.
- Å kommentere vekk kode bruk # -> kjøre kode uten å slette kode eller Ctr1
- Jupyter Notebook >> New >> Python 3: Write code cells. If want to write texts -> Cell >> Cell
Type >> Markdown
- To see if a package numpy is installed -> Anaconda prompt >> pip show numpy
Floating point values have the f suffix. We can also specify the precision: the number of decimal
places. The precision is a value that goes right after the dot character.
$ python format_floats.py
12.30
12.30000
- An array data structure belongs to the "must-import" category. To use an array in Python,
you'll need to import this data structure from the NumPy package or the array module.
- An array is also a data structure that stores a collection of items. Like lists, arrays are
ordered, mutable, enclosed in square brackets, and able to store non-unique items. But
when it comes to the array's ability to store different data types, the answer is not as
straightforward. It depends on the kind of array used. To use arrays in Python, you need to
import either an array module or a NumPy package.
- Arrays need to be declared. Lists don't, since they are built into Python. Lists are created by
simply enclosing a sequence of elements into square brackets. Creating an array, on the
other hand, requires a specific function from either the array module (i.e., array.array()) or
NumPy package (i.e., numpy.array()). Because of this, lists are used more often than arrays.
- Arrays can store data very compactly and are more efficient for storing large amounts of
data.
- Arrays are great for numerical operations; lists cannot directly handle math operations. For
example, you can divide each element of an array by the same number with just one line of
code. If you try the same with a list, you'll get an error.
- It's possible to do a mathematical operation with a list, but it's much less efficient:
In, Python += adds another value with the variable's value and assigns the new value to
the variable
Regular mistakes: wrong name of function, long codes without testing small portions first for easier
troubleshooting
Good practice: use print function in Funksjoner so that we know that variables are attached the right
values.
A variable defined inside a function is local to it. When the function ends, this variable is destroyed.
https://www.programiz.com/python-programming/global-local-nonlocal-variables
True, False in Python has to be with the capital beginning letter ( not true, false)
(S += S) is (S = S + S)