Created
September 1, 2020 14:17
-
-
Save alexmacniven/4b579080d04dfd699afb2451b4d719a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = [3, 5, 7] | |
# This is our function `print_list` which takes `x` as an argument. | |
# `x` is just a name we give it, it could be anything like... `cat` or `dog` | |
# In real-world examples you would give your arguments meaningful names like `list_to_print` | |
def print_list(x): | |
# Likewise `i` is just a name we've given to a variable | |
# You could call this `item` or in this case `number` | |
for i in range(0, len(x)): | |
# The line above is going to count from 0 to the length of the list we | |
# pass as the `x` parameter, in this case 3. So it will count 0, 1, 2 | |
# because the last number in the range is excluded. | |
# The for loop means `i` is going to equal 0 on the first loop, then | |
# 1 on the next loop, and finally 2 | |
# The print statement below is going to print the item in the list `n` | |
# at the position of `i`. | |
# Remember lists are Zero Indexed, the first item is at index 0. | |
# On the first loop the statement will print the item at index 0 | |
# and then the item at index 1, lastly the item at index 2 | |
print(n[i]) | |
# Here we pass the list `n` to the `print_list` function | |
print_list(n) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment