Coding in Python 16 - For Loops

From LearnLinux.tv Wiki
Revision as of 20:03, 17 March 2019 by Jay (talk | contribs) (Created page with "== Overview == In video number 16 of the Coding in Python series, we'll check out for loops. {| class="wikitable" |- ! Relevant Links |- | [https://youtu.be/GW6DlAjZdks Origi...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Overview

In video number 16 of the Coding in Python series, we'll check out for loops.

Relevant Links
Original Video


Commands Used in this Video

Simple for loop

#!/usr/bin/env python3


foods = ["pizza", "tacos", "hamburger", "salad"]

for f in foods:
    print(f)

For loop with a string

#!/usr/bin/env python3


sentence = "Python is awesome!"

for c in sentence:
    print(c)

For loop with random

#!/usr/bin/env python3


import random

counter = random.randint(5,10)

number = 1

for i in range(counter):
    print(number)
    number += 1