πŸŽ“ A1Learner
πŸ”
0 of 52 lessons completed

Python Intermediate Intro

Intermediate Python is Python for bigger programs. A bigger program does one real job, like cleaning a file or fetching a page.

Words in alphabet order

sorted() orders words by alphabet. The first lesson adds a small rule, a key, that orders them by length instead.

words = ["pear", "fig", "banana"]
print(sorted(words))

Build a new list in one line

A list comprehension makes a new list from an old one. Each old item is squared.

nums = [1, 2, 3, 4]
print([n * n for n in nums])

A class that prints nicely

__str__ returns the text print() shows for an object. The class below uses it.

class Book:
    def __init__(self, title):
        self.title = title

    def __str__(self):
        return "Book: " + self.title

print(Book("Dune"))

Example

words = ["pear", "fig", "banana", "kiwi"]
longest = words[0]
shortest = words[0]
for word in words:
    if len(word) > len(longest):
        longest = word
    if len(word) < len(shortest):
        shortest = word
print("Shortest:", shortest)
print("Longest:", longest)
print("All in order:", sorted(words))

Key points

  • Python Beginner taught the pieces: variables, loops, functions, lists, classes, files.
  • Intermediate Python joins those pieces into programs that do real jobs.
  • Each lesson adds one tool or one habit. Each lesson ends with a working program.
  • Python Advanced comes after this course. It covers the deep parts, like decorators and asyncio.
  • A lesson takes about six minutes. The course holds 52 lessons in 13 entries.

In this example, the list holds four fruit words. The loop checks each word against the longest and shortest found so far. A longer word replaces the longest. A shorter word replaces the shortest. The last line prints the whole list in alphabet order.

Note

Nothing here needs new software. The same Python 3 from Beginner is enough.

Try it Yourself

Edit the code, then press Run.

Running is simulated Β· Python Playground

Exercise

What does this course teach you to build?