We studied new string functions and new list functions. Then, We studies loops. we began with for–loop (which is also called foreach loop). for-loop iterates over a list and “visits” all of the items in a sequentially order. We wrote a for-loop to iterate over a list of strings (i.e.: [‘danny’, ‘orli’, ‘yossi’]) and a a for-loop to iterate over a list of numbers (i.e.: [2, -200, 3, 4, 100]). We saw the break command, which exits the for current loop immediately. as an example we wrote a python code which sums up numbers in a given list- until we reach the end of the list or until we reach a a total sum of 100 (using break). In the last part of the lesson we saw how to write a nested for-loop, which is a loop inside a loop (parent-child loop). we used it to iterate through a parent list which contains a child list. i.e.: [ [11, 9, 100] , [-5, 1000, 200], [5], [2, 4, 2, 1] ]. we saw that break in the inner loop only exists the inner loop, but the parent loop keeps going on
More topics covered:
- Sorted command – sort and also returns a new list
- reversed command – reverse and also returns a new list
- Debugger usage – introduction
- boolean
- print using f: print ( f'{a} + {b} = {c}’)
Links:
