Swift for Python Developers
Move from Python to Swift through static types, value semantics, optionals, Unicode, protocols, and ARC. Complete 48 multi-file exercises, build a parcel desk, and port two complete Python programs.
Python and Swift side by side
The same program in Python and in Swift, from the lessons of this course.
Bindings and Mutation
Python names refer to objects. Assigning another object rebinds a name, and a later assignment can even use a different type. A second name keeps its own reference to the earlier object. Type annotations do not enforce these assignments at runtime.
Python1label = "draft"2saved = label3label = 174print(saved, label)Swift1let saved = "draft"2var label = saved3label = "ready"4print(saved, label)Strings and Interpolation
Python f-strings embed expressions inside braces. Swift interpolation puts an expression inside \(...). Both construct a new string. Swift joins strings with +, and methods such as hasPrefix answer text questions without converting the text to a number.
Python1done = 32print(f"progress={done * 25}%")3print("report.csv".startswith("report"))Swift1let done = 32print("progress=\(done * 25)%")3print("report.csv".hasPrefix("report"))Switch and Patterns
Python structural matching and Swift switch both choose a matching pattern, but their syntax and exhaustiveness rules differ. Swift requires all possibilities to be covered. For an open set such as integers, a default case handles remaining values.
Python1command = "pause"2match command:3 case "pause" | "stop":4 print("idle")5 case _:6 print("running")Swift1let command = "pause"2switch command {3case "pause", "stop": print("idle")4default: print("running")5}Functions and Labels
Python callers can pass arguments by parameter name unless a signature restricts them. Swift separates the external argument label used by callers from the internal parameter name. By default these names match; an underscore suppresses an external label.
Python1def echo(sound, times):2 return sound * times3print(echo("ha", times=3))Swift1func echo(_ sound: String, times count: Int) -> String {2 return String(repeating: sound, count: count)3}Dictionaries and Missing Keys
Python dictionary subscripting raises KeyError when a key is absent; get can return a fallback instead. Swift dictionary subscripting returns an optional. Assigning nil through that subscript removes an entry.
Python1settings = {"font": 14, "gap": 2}2del settings["gap"]3print(settings.get("gap", 8))4print(len(settings))Swift1var settings = ["font": 14, "gap": 2]2settings["gap"] = nil3print(settings["gap"] ?? 8)4print(settings.count)Structs and Independent Copies
A Python class instance, including a dataclass instance, is an object reached through references. Assigning it to another name does not make a new instance. Swift struct declares a value type, so assignment gives another value whose stored value properties…
Python1from dataclasses import dataclass2@dataclass3class Heading:4 direction: str5first = Heading("north")6second = first7second.direction = "west"8print(first.direction, second.direction)Swift1struct Heading {2 var direction: String3 mutating func turnWest() { direction = "west" }4}
Syllabus
10 chapters48 lessons1 project48 challenges99 quiz questionsStarting Swift
5 lessonsText and Decisions
5 lessonsControl Flow
5 lessonsFunctions and Arrays
5 lessonsCollection Tools
5 lessonsValues and References
5 lessonsFailures and Abstraction
6 lessonsDesigning Types
6 lessonsParcel Desk Project
4 lessonsPython Ports
2 lessonsFrequently asked questions
Who is Swift for Python Developers for?
For people who already write Python and want to learn Swift. Each lesson starts from Python you know and shows how Swift does the same thing, so you skip the beginner basics.
Do I need to know Swift already?
No. The course starts with your first Swift program. You need Python basics: variables, conditions, loops, functions and collections.
How many lessons does Swift for Python Developers have?
Swift for Python Developers contains 48 interactive lessons you can complete at your own pace.
What does Swift for Python Developers cover?
The course is organized into chapters covering: Starting Swift, Text and Decisions, Control Flow, Functions and Arrays, and more.
Is Swift for Python Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.