From ecca009a780d1ad431203e3cce8efdefdc9d2176 Mon Sep 17 00:00:00 2001 From: Joe James Date: Tue, 25 Feb 2020 08:06:39 -0600 Subject: [PATCH] Create for_loops_1 --- python/for_loops_1 | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 python/for_loops_1 diff --git a/python/for_loops_1 b/python/for_loops_1 new file mode 100644 index 0000000..8871ad7 --- /dev/null +++ b/python/for_loops_1 @@ -0,0 +1,17 @@ +# m is a list of integers +m = [5,7,6,8,1,4,2,7] + +# here number is just a variable name +# the for loop iterates each item in list m +# the print statement prints the number and the number squared +for number in m: + print(number, number**2) + +# here i is a variable for the list index +# the for loop iterates from 0 (first item) +# through len(m) which is the last item +# the print statement prints the index i, +# and the i'th item in the list, m[i] +print() +for i in range(len(m)): + print(i, m[i])