Coding in Python 16 – For Loops

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

YouTube player

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

Brand-New Course!

Check out Jay’s new course on Ansible and start automating today!

Discount Vouchers


Receive 5% off an LPI exam voucher!

Exclusive Member Features

Support the channel and receive exclusive perks!