Menu
CoddyTech
Course

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.

  1. 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.

    Python
    1label = "draft"2saved = label3label = 174print(saved, label)
    Swift
    1let saved = "draft"2var label = saved3label = "ready"4print(saved, label)
  2. 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.

    Python
    1done = 32print(f"progress={done * 25}%")3print("report.csv".startswith("report"))
    Swift
    1let done = 32print("progress=\(done * 25)%")3print("report.csv".hasPrefix("report"))
  3. 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.

    Python
    1command = "pause"2match command:3    case "pause" | "stop":4        print("idle")5    case _:6        print("running")
    Swift
    1let command = "pause"2switch command {3case "pause", "stop": print("idle")4default: print("running")5}
  4. 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.

    Python
    1def echo(sound, times):2    return sound * times3print(echo("ha", times=3))
    Swift
    1func echo(_ sound: String, times count: Int) -> String {2    return String(repeating: sound, count: count)3}
  5. 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.

    Python
    1settings = {"font": 14, "gap": 2}2del settings["gap"]3print(settings.get("gap", 8))4print(len(settings))
    Swift
    1var settings = ["font": 14, "gap": 2]2settings["gap"] = nil3print(settings["gap"] ?? 8)4print(settings.count)
  6. 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…

    Python
    1from dataclasses import dataclass2@dataclass3class Heading:4    direction: str5first = Heading("north")6second = first7second.direction = "west"8print(first.direction, second.direction)
    Swift
    1struct Heading {2    var direction: String3    mutating func turnWest() { direction = "west" }4}

Syllabus

10 chapters48 lessons1 project48 challenges99 quiz questions

More courses for Python developers

Learn Swift from another language

Frequently 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.

Coddy programming languages illustration

Start Swift for Python Developers for free

Get started