Menu
CoddyTech
Course

Rust for Python Developers

Build on Python names, collections, exceptions and classes to learn Rust ownership, borrowing, enums and traits. Complete 48 multi-file tasks, build a parcel depot and port two Python programs.

Python and Rust side by side

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

  1. Output and Comments

    Python executes top-level statements; a Rust executable starts at fn main(). Python uses # for comments, while Rust uses // or /* ... */. Markers inside string literals are data. Python f-strings evaluate expressions in braces. Rust println! is a macro that…

    Python
    1# This line is ignored.2print("level", end=":")3print(f"{2 + 3} # literal")
    Rust
    1fn main() {2    // This line is ignored.3    print!("level:");4    println!("{} # literal", 2 + 3);5}
  2. Boolean Conditions

    Python conditions use truthiness: empty collections, zero and None are false-like. Python and and or return one of their operands, which need not be a boolean. Rust conditions require bool, and && and || produce booleans. Both languages short-circuit, so the…

    Python
    1items = []2chosen = items or "fallback"3print(chosen)4print(bool(items))
    Rust
    1fn main() {2    let items: Vec<i32> = Vec::new();3    let present = !items.is_empty();4    println!("{}", present);5    println!("{}", present && items[0] == 9);6}
  3. Functions and Returns

    Python functions accept objects dynamically unless their body or an external tool imposes constraints. Rust signatures state parameter and return types, and call sites must satisfy them. Python requires return to return a non-None value. Rust permits an…

    Python
    1def differs(left, right):2    return left != right3print(differs("a", "b"))4print(differs("a", "a"))
    Rust
    1fn differs(left: char, right: char) -> bool { left != right }2fn main() {3    println!("{}", differs('a', 'b'));4    println!("{}", differs('a', 'a'));5}
  4. Ownership and Moves

    Python assignment binds another name to the same object; it does not give that name exclusive ownership. Mutating a shared list is visible through aliases. Rust gives a value such as Vec one owner. Assigning it to another binding moves ownership, making the…

    Python
    1first = [6, 8]2second = first3second.reverse()4print(first[0])5print(first is second)
    Rust
    1fn main() {2    let first = vec![6, 8];3    let mut second = first;4    second.reverse();5    let mut independent = second.clone();6    independent.clear();7    println!("{}", second[0]);8    println!("{}", independent.len());9}
  5. Strings and UTF-8

    Python str is a Unicode text sequence: indexing gives a one-character string representing a code point. Rust String stores UTF-8 and str views valid UTF-8 text. Rust does not support integer indexing into text, because a byte offset is not generally a…

    Python
    1word = "éx"2print(word[0])3print(word.encode("utf-8")[0])
    Rust
    1fn main() {2    let word = "éx";3    println!("{}", word.chars().next().unwrap());4    println!("{}", word.get(0..1).is_none());5}
  6. Option and Matching

    Python APIs often return None when no result exists. Rust makes that possibility part of the type using Option<T>, whose variants are Some(value) and None. Some(0) and Some(false) are present values, not absence. Pattern matching or methods such as map let…

    Python
    1values = [0]2first = values[0] if values else None3missing = values[2] if len(values) > 2 else None4print(first is None)5print(missing is None)
    Rust
    1fn main() {2    let values = vec![0];3    println!("{}", values.get(0).is_none());4    println!("{}", values.get(2).is_none());5}

Syllabus

10 chapters48 lessons1 project48 challenges99 quiz questions

More courses for Python developers

Learn Rust from another language

Frequently asked questions

Who is Rust for Python Developers for?

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

Do I need to know Rust already?

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

How many lessons does Rust for Python Developers have?

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

What does Rust for Python Developers cover?

The course is organized into chapters covering: First Rust Programs, Decisions and Loops, Functions and Sequences, Ownership and Borrowing, and more.

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

Get started