Python for Rust Developers
Bring Rust experience to Python: replace ownership assumptions with object references, compare Option and exceptions, translate iterators and trait-based designs, and build a connected order processor.
Rust and Python side by side
The same program in Rust and in Python, from the lessons of this course.
Macros to print
Rust uses println! with a format string. Python print is a function: separate arguments are separated by a space, and a newline is appended by default. Python single and double quotes both delimit strings; there is no separate character type like Rust char.…
Rust1// A comment for readers2println!("Status: {}", "ready");3println!("Don't stop");Python1# A comment for readers2print("Status:", "ready")3print("Don't stop")Option and None
Rust expresses optional data with Option<T> and normally handles its variants by matching or combinators. Python commonly uses a value or the singleton None. There is no wrapper to unwrap before using a nonmissing value, and no compiler forces you to handle…
Rust1let seats: Option<i32> = None;2println!("{}", seats.is_none());3println!("{}", false);Python1seats = None2print(seats is None)3available = False4print(available)Vec to list
A Python list is a growable ordered collection, often replacing Vec<T>. It holds object references without an enforced uniform element type. Indexes start at zero; negative indexes count from the end. Python items[-1] reads the last element, while Rust uses…
Rust1let mut items = vec![4, 8];2items.push(12);3println!("{}", items[items.len() - 1]);4println!("{:?}", &items[..2]);Python1items = [4, 8]2items.append(12)3print(items[-1])4print(items[:2])Borrowed Iteration to for
Rust chooses ownership behavior through iter, iter_mut, and into_iter. Python for value in values binds the loop name to each element object and does not consume the list or create an exclusive borrow. Rebinding an integer loop name does not replace a slot…
Rust1let values = vec![2, 4];2for value in &values { println!("{}", value); }3for i in 0..3 { println!("{}", i); }Python1for value in [2, 4]:2 print(value)3for i in range(3):4 print(i)Functions and Shared Objects
Python def introduces a function, with parameters named in parentheses and an indented body. Use return explicitly: a final expression alone is discarded and falling through returns None. Rust functions declare parameter types and can return a tail expression…
Rust1fn twice(value: i32) -> i32 { value * 2 }2println!("{}", twice(4));Python1def twice(value):2 return value * 23print(twice(4))Text Input and Formatting
Rust read_line fills a mutable buffer and returns a Result. Python input() returns a string with its trailing newline removed, and raises EOFError if input is exhausted. Parse with int before doing integer arithmetic. strip() removes surrounding whitespace…
Rust1let label = " Green tea ".trim();2let cents = 305;3println!("{}: {}.{:02}", label, cents / 100, cents % 100);Python1label = " Green tea ".strip()2cents = 3053print(f"{label}: {cents // 100}.{cents % 100:02d}")
Syllabus
10 chapters48 lessons1 project48 challenges99 quiz questionsFrom Rust to Python
6 lessonsValues and Decisions
5 lessonsOwnership and Collections
5 lessonsIteration and Transformations
5 lessonsFunctions and Closures
5 lessonsErrors and Modules
5 lessonsInstances and Shared State
6 lessonsComposition and Dispatch
5 lessonsProject: Order Processing
4 lessonsApply Your Rust Experience
2 lessonsFrequently asked questions
Who is Python for Rust Developers for?
For people who already write Rust and want to learn Python. Each lesson starts from Rust 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 Rust basics: variables, conditions, loops, functions and collections.
How many lessons does Python for Rust Developers have?
Python for Rust Developers contains 48 interactive lessons you can complete at your own pace.
What does Python for Rust Developers cover?
The course is organized into chapters covering: From Rust to Python, Values and Decisions, Ownership and Collections, Iteration and Transformations, and more.
Is Python for Rust Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.