ungleich-learning-circle/balazs/python-the-hard-way/ex32/notes_n_drills.org
2020-05-29 16:58:16 +02:00

44 lines
1.2 KiB
Org Mode

* Drills
** Take a look at how you used range . Look up the range function to understand it.
tldr, a "function" that generates a sequence of numbers:
class range(start, stop[, step]):
start
The value of the start parameter (or 0 if the parameter was not supplied)
stop
The value of the stop parameter
step
The value of the step parameter (or 1 if the parameter was not supplied)
-------
I found it among python 3.8.3 built-in functions.
but!
Turns out it's not a function after all!
It's an immutable sequence type.
"a range object will always take the same (small) amount of memory" ... "as it only stores the start, stop and step values" and generates numbers on the fly
note: similar in shell is: seq
source: https://docs.python.org/3/library/stdtypes.html#range
** Could you have avoided that for-loop entirely on line 22 and just assigned range(0,6) directly to elements?
Do you mean line 21 book? (typo)
Yes! Because range will generate a list that can be appended added as is.
** Find the Python documentation on lists and read about them. What other operations can you do to lists besides append?
extend, insert, remove, pop, clear, index, count, sort, reverse, copy
fascinating! programming is cool! you can do so much with it