Python for Ruby Developers
Transfer Ruby experience to Python through concrete contrasts in truthiness, returns, blocks, hash defaults, and object state. Practice multi-file programs and build a four-step order processor.
Ruby and Python side by side
The same program in Ruby and in Python, from the lessons of this course.
Strings and Interpolation
Ruby and Python both allow top-level statements and use # for comments. Ruby interpolates #{name} inside double-quoted strings; single-quoted Ruby strings normally leave that syntax literal. Python does not interpolate ordinary quoted strings. Prefix an…
Ruby1name = 'Ada'2puts "Hi #{name}"3puts 'Hi #{name}'Python1name = 'Ada'2print(f"Hi {name}")3print("Hi {name}")nil Becomes None
Python spells the absence singleton None and its booleans True and False. Ruby uses nil, true, and false. Test absence with value is None, corresponding to the intent of Ruby value.nil?. The Python test checks identity with the singleton, not whether a…
Ruby1value = nil2puts value.nil?3puts falsePython1value = None2print(value is None)3print(False)Array Methods and Lists
A Python list is the usual counterpart of a Ruby array: it is ordered, mutable, growable, and stores object references. Both support negative indexes. Python slicing excludes the stop index, corresponding to the intent of a Ruby exclusive range slice.…
Ruby1items = [4, 8]2saved = items.push(12)3p savedPython1items = [4, 8]2saved = items.append(12)3print(saved)4print(items[-1])each and Python for
Ruby commonly iterates with each and a block; Python uses a for statement over an iterable. Python has no block parameter bars. The loop target receives each element, not its index. Rebinding a target containing an integer does not replace the element in…
Ruby1values = [2, 4]2values.each { |value| value += 1 }3p values4p (0..2).to_aPython1values = [2, 4]2for value in values:3 value += 14print(values)5print(list(range(0, 2)))Explicit Return Values
Ruby methods return the value of their final expression unless an explicit return exits earlier. Python functions do not implicitly return that expression: falling off the end returns None. Define functions with def and a colon, then use return when the…
Ruby1def twice(value)2 value * 23end4puts twice(4)Python1def twice(value):2 value * 23print(twice(4))4def explicit_twice(value):5 return value * 26print(explicit_twice(4))gets, input, and Formatting
Ruby gets reads a line including its newline and returns nil at end of input. Python input removes the trailing newline and raises EOFError when no line is available. Neither automatically parses numbers. Ruby strip and Python strip remove surrounding…
Ruby1label = ' Green tea '.strip2cents = 3053puts "#{label}: #{cents / 100}.#{format('%02d', cents % 100)}"Python1label = ' Green tea '.strip()2cents = 3053print(f'{label}: {cents // 100}.{cents % 100:02d}')
Syllabus
10 chapters48 lessons1 project48 challenges99 quiz questionsFrom Ruby to Python
6 lessonsValues and Decisions
5 lessonsCollections and References
5 lessonsIteration and Transformations
5 lessonsFunctions and Closures
5 lessonsReliable Python Programs
5 lessonsObjects and Shared State
6 lessonsComposition and Inheritance
5 lessonsProject: Order Processing
4 lessonsApply Your Ruby Experience
2 lessonsFrequently asked questions
Who is Python for Ruby Developers for?
For people who already write Ruby and want to learn Python. Each lesson starts from Ruby 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 Ruby basics: variables, conditions, loops, functions and collections.
How many lessons does Python for Ruby Developers have?
Python for Ruby Developers contains 48 interactive lessons you can complete at your own pace.
What does Python for Ruby Developers cover?
The course is organized into chapters covering: From Ruby to Python, Values and Decisions, Collections and References, Iteration and Transformations, and more.
Is Python for Ruby Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.