Open main menu

CDOT Wiki β

Changes

OPS435 Python Lab 3

8 bytes added, 11:17, 3 June 2017
PART 3 - Iterating Over Lists
new_list_of_numbers = square_list(list_of_numbers)
new_list_of_numbers
</source>The above is just one example of quick, powerful, for loops mixed with lists. But be careful when passing lists into functions. When you give a function a list as an argument, it is the actual list reference and NOT a copy. This means a function can completely change the list without making a new list. While you do have to be careful this is also useful, a function can modify any given list, without have to return or store it.<br><br>
:#To demonstrate, issue the following:<source>
list_of_numbers = [ 1, 5, 2, 6, 8, 5, 10, 2 ]
13,420
edits