Menu
CoddyTech
Course

Python for Swift Developers

Transfer Swift experience to Python: contrast value and reference semantics, optionals and exceptions, argument labels and defaults, protocols and duck typing, then build a connected order processor.

Swift and Python side by side

The same program in Swift and in Python, from the lessons of this course.

  1. Printing and Strings

    Swift and Python print both normally separate arguments with spaces and finish with a newline. Python permits single or double quotes for strings; Swift normally uses double quotes and has a distinct Character type. Python has no separate character type. Use…

    Swift
    1// Status for a reader2print("Status:", "ready")3print("Don't stop")
    Python
    1# A comment for readers2print("Status:", "ready")3print("Don't stop")
  2. Optionals and None

    Swift models absence with Optional and unwraps it through binding, matching, chaining, or coalescing. Python commonly uses a value or None, without a compiler-enforced unwrap step. Check is None to distinguish missing data from zero or empty text. Python does…

    Swift
    1let seats: Int? = nil2print(seats == nil)3let available = false4print(available)
    Python
    1seats = None2print(seats is None)3available = False4print(available)
  3. Array to list

    Python lists and Swift arrays are ordered and zero-indexed, but Python lists store references without an enforced homogeneous element type. Python negative indexes count backward and slices exclude their stop bound. Swift uses collection indexes and ranges; a…

    Swift
    1var items = [4, 8]2items.append(12)3print(items.last!)4print(Array(items.prefix(2)))
    Python
    1items = [4, 8]2items.append(12)3print(items[-1])4print(items[:2])
  4. for and Half-Open Ranges

    Swift for-in and Python for both visit iterable values. Python range excludes its stop, corresponding to Swift half-open ranges rather than closed ranges. Python permits a step argument, including a negative step. The Python loop name binds each object…

    Swift
    1for value in [2, 4] { print(value) }2for i in 0..<3 { print(i) }
    Python
    1for value in [2, 4]:2    print(value)3for i in range(3):4    print(i)
  5. Functions and Explicit Return

    Python def introduces a function with named parameters and an indented suite. It does not require parameter types. Use return explicitly; falling through returns None. Swift can infer returns in some single-expression functions, but Python def does not use…

    Swift
    1func twice(_ value: Int) -> Int { value * 2 }2print(twice(4))
    Python
    1def twice(value):2    return value * 23print(twice(4))
  6. Input and String Formatting

    Swift readLine returns an optional string; Python input returns a string or raises EOFError. Convert integer text with int before arithmetic. strip removes outer whitespace and split without arguments splits whitespace runs. Python f-strings embed expressions…

    Swift
    1import Foundation2let label = "  Green tea  ".trimmingCharacters(in: .whitespaces)3let cents = 3054print(String(format: "%@: %d.%02d", label, cents / 100, cents % 100))
    Python
    1label = "  Green tea  ".strip()2cents = 3053print(f"{label}: {cents // 100}.{cents % 100:02d}")

Syllabus

10 chapters48 lessons1 project48 challenges99 quiz questions

Apply Your Swift Experience

2 lessons

More courses for Swift developers

Learn Python from another language

Frequently asked questions

Who is Python for Swift Developers for?

For people who already write Swift and want to learn Python. Each lesson starts from Swift you know and shows how Python does the same thing, so you skip the beginner basics.

Do I need to know Python already?

No. The course starts with your first Python program. You need Swift basics: variables, conditions, loops, functions and collections.

How many lessons does Python for Swift Developers have?

Python for Swift Developers contains 48 interactive lessons you can complete at your own pace.

What does Python for Swift Developers cover?

The course is organized into chapters covering: From Swift to Python, Values and Decisions, Value Types to Shared Objects, Iteration and Transformations, and more.

Is Python for Swift 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 Python for Swift Developers for free

Get started