Menu
CoddyTech
Course

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.

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

    Ruby
    1name = 'Ada'2puts "Hi #{name}"3puts 'Hi #{name}'
    Python
    1name = 'Ada'2print(f"Hi {name}")3print("Hi {name}")
  2. 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…

    Ruby
    1value = nil2puts value.nil?3puts false
    Python
    1value = None2print(value is None)3print(False)
  3. 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.…

    Ruby
    1items = [4, 8]2saved = items.push(12)3p saved
    Python
    1items = [4, 8]2saved = items.append(12)3print(saved)4print(items[-1])
  4. 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…

    Ruby
    1values = [2, 4]2values.each { |value| value += 1 }3p values4p (0..2).to_a
    Python
    1values = [2, 4]2for value in values:3    value += 14print(values)5print(list(range(0, 2)))
  5. 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…

    Ruby
    1def twice(value)2  value * 23end4puts twice(4)
    Python
    1def twice(value):2    value * 23print(twice(4))4def explicit_twice(value):5    return value * 26print(explicit_twice(4))
  6. 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…

    Ruby
    1label = '  Green tea  '.strip2cents = 3053puts "#{label}: #{cents / 100}.#{format('%02d', 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 Ruby Experience

2 lessons

More courses for Ruby developers

Learn Python from another language

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

Coddy programming languages illustration

Start Python for Ruby Developers for free

Get started