Ruby has the concepts of blocks, which are essentially syntactic sugar around a section of code; they are a way to create closures and pass them to another method which may or may not use the block. A block can be invoked later on through a yield statement.

For example, a simple definition of an each method on Array might be something like:

class Array
  def each
    for i in self  
      yield(i)     # If a block has been passed, control will be passed here.
    end  
  end  
end  

Then you can invoke this like so:

# Add five to each element.
[1, 2, 3, 4].each{ |e| puts e + 5 }
> [6, 7, 8, 9]

Python has anonymous functions/closures/lambdas, but it doesn't quite have blocks since it's missing some of the useful syntactic sugar. However, there's at least one way to get it in an ad-hoc fashion. See, for example, here.

Answer from John Feminella on Stack Overflow
🌐
Learn Enough
learnenough.com › blog › ruby-vs-python
Ruby vs Python: What’s The Difference & How To Choose?
January 12, 2024 - Django, a high-level web framework, ... up. If the Python interpreter is often compared to executable pseudocode, Ruby is more like expressive poetry....
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-vs-ruby
Python vs Ruby - GeeksforGeeks
July 11, 2025 - Both have clean syntax and are easily readable. Both use an interactive prompt called IRB. Objects are strongly and dynamically typed. Both use embedded doc tools. A GNU Debugger(gdb) style is available for each language.
Discussions

What does Ruby have that Python doesn't, and vice versa? - Stack Overflow
Instead explain what Ruby's lambdas can do that Python's can't. No subjectivity. Example code is good! Don't have several differences in one answer, please. And vote up the ones you know are correct, and down those you know are incorrect (or are subjective). Also, differences in syntax is not ... More on stackoverflow.com
🌐 stackoverflow.com
Benefits of moving from Python to Ruby?

When it comes to scripting languages, the objective differences are very nuanced. Largely, it depends on what you want to do. Python, for example, is extremely popular in the data sciences. A complementary example for Ruby would be rapid application development with Ruby on Rails, a web framework that allows you to build web applications very quickly. Another example would be building an API using Ruby's Sinatra library. Python also has web frameworks, so it's not as if Ruby has an exclusive claim to this benefit, but many developers find tools like Ruby on Rails and Sinatra very satisfying and beneficial to work with.

My recommendation would be to give Ruby an honest shot. Don't make the mistake of simply trying to write Python code using Ruby. Really dig in to what makes Ruby, Ruby. If you enjoy it, then you've added another language to your tool belt. If you don't, you might walk away with some ideas about development that you can apply to Python.

More on reddit.com
🌐 r/ruby
40
32
May 31, 2022
Ruby vs. Python comes down to the for loop

Your python example is unnecessarily complicated. You can achieve the exact same thing just as simple as you would in your Ruby example. Perhaps you are not aware of the existence of "yield" in python?

class Stuff:
    def __init__(self):
        self.a_list = [1, 2, 3, 4]

    def __iter__(self):
        for val in self.a_list:
            yield val
More on reddit.com
🌐 r/programming
4
0
April 22, 2024
Python vs Ruby! Which is easier?

Having used both, I'd say Ruby, especially if you're already an experienced programmer who's more used to C syntax. Python feels restrictive to me, Ruby has powers that reveal themselves as you learn more. But neither are my preferred language.

More on reddit.com
🌐 r/ProgrammerHumor
15
0
October 24, 2022
People also ask

Is Ruby better than Python?
This question can set off a great debate that can easily devolve into madness. If you look at Python vs Ruby, they certainly have their similarities. However, Python is often better when it comes to educational use and for making quick apps and programs, while Ruby is usually the choice for those who want to make commercial web apps. The choice depends on your (or your project’s) needs and ultimately comes down to personal preference.
🌐
hackr.io
hackr.io › home › articles › programming
Ruby vs Python: Differences You Should Know [Updated] 2026
Which is more popular, Ruby or Python?
When it comes to use in web development, Ruby is generally much more popular. Python tends to be more popular for use in academic and scientific circles and purposes.
🌐
hackr.io
hackr.io › home › articles › programming
Ruby vs Python: Differences You Should Know [Updated] 2026
How do Ruby and Python syntax differ in 2024?
Python is favored for its simpler, more natural language syntax, while Ruby is known for its expressive and flexible nature.
🌐
learnenough.com
learnenough.com › blog › ruby-vs-python
Ruby vs Python: What’s The Difference & How To Choose?
🌐
Ruby-Doc.org
ruby-doc.org › home › ruby vs python – a comprehensive comparison for developers
Ruby vs Python - A Comprehensive Comparison for Developers - Ruby-Doc.org
July 11, 2025 - Ruby prioritizes developer happiness. It embraces multiple programming paradigms (object-oriented, functional, imperative) and gives developers freedom to choose their approach. ... Focus on elegant syntax. Heavy use of meta-programming and DSLs (Domain-Specific Languages). Python is driven by simplicity and readability (read more).
🌐
Hackr
hackr.io › home › articles › programming
Ruby vs Python: Differences You Should Know [Updated] 2026
January 30, 2025 - Notice the use of print as opposed to puts in Ruby, and the absence of a semicolon to end the line. In Python, white spaces are significant and indicative of a block of code. For example, Note that the code on the right will give syntax error as there are no other white spaces.
Top answer
1 of 16
34

Ruby has the concepts of blocks, which are essentially syntactic sugar around a section of code; they are a way to create closures and pass them to another method which may or may not use the block. A block can be invoked later on through a yield statement.

For example, a simple definition of an each method on Array might be something like:

class Array
  def each
    for i in self  
      yield(i)     # If a block has been passed, control will be passed here.
    end  
  end  
end  

Then you can invoke this like so:

# Add five to each element.
[1, 2, 3, 4].each{ |e| puts e + 5 }
> [6, 7, 8, 9]

Python has anonymous functions/closures/lambdas, but it doesn't quite have blocks since it's missing some of the useful syntactic sugar. However, there's at least one way to get it in an ad-hoc fashion. See, for example, here.

2 of 16
28

Python Example

Functions are first-class variables in Python. You can declare a function, pass it around as an object, and overwrite it:

def func(): print "hello"
def another_func(f): f()
another_func(func)

def func2(): print "goodbye"
func = func2

This is a fundamental feature of modern scripting languages. JavaScript and Lua do this, too. Ruby doesn't treat functions this way; naming a function calls it.

Of course, there are ways to do these things in Ruby, but they're not first-class operations. For example, you can wrap a function with Proc.new to treat it as a variable--but then it's no longer a function; it's an object with a "call" method.

Ruby's functions aren't first-class objects

Ruby functions aren't first-class objects. Functions must be wrapped in an object to pass them around; the resulting object can't be treated like a function. Functions can't be assigned in a first-class manner; instead, a function in its container object must be called to modify them.

def func; p "Hello" end
def another_func(f); method(f)[] end
another_func(:func)      # => "Hello"

def func2; print "Goodbye!"
self.class.send(:define_method, :func, method(:func2))
func                     # => "Goodbye!"

method(:func).owner      # => Object
func                     # => "Goodbye!"
self.func                # => "Goodbye!"    
🌐
Guru99
guru99.com › home › python › python vs ruby – difference between them
Python vs Ruby – Difference Between Them
August 12, 2024 - Ruby has a clean and easy syntax, which allows a new developer to learn very quickly and easily. Just like Python, it’s open source.
Find elsewhere
🌐
Reddit
reddit.com › r/ruby › benefits of moving from python to ruby?
r/ruby on Reddit: Benefits of moving from Python to Ruby?
May 31, 2022 -

Question from someone who invested much time in Python. What benefits Ruby has to convince to move? Instead continue with Python?

Top answer
1 of 13
34

When it comes to scripting languages, the objective differences are very nuanced. Largely, it depends on what you want to do. Python, for example, is extremely popular in the data sciences. A complementary example for Ruby would be rapid application development with Ruby on Rails, a web framework that allows you to build web applications very quickly. Another example would be building an API using Ruby's Sinatra library. Python also has web frameworks, so it's not as if Ruby has an exclusive claim to this benefit, but many developers find tools like Ruby on Rails and Sinatra very satisfying and beneficial to work with.

My recommendation would be to give Ruby an honest shot. Don't make the mistake of simply trying to write Python code using Ruby. Really dig in to what makes Ruby, Ruby. If you enjoy it, then you've added another language to your tool belt. If you don't, you might walk away with some ideas about development that you can apply to Python.

2 of 13
27

Ruby delivers on the promise of being "optimized for programmer happiness." But I think that in order to experience that you have to become fairly immersed. In fact, some of the best parts seem outright offensive at first (question marks in method names?!). No language is perfect. But once you get past the idiosyncrasies, I honestly do think Ruby feels better. That's pretty esoteric, so I'll try to call out some specifics as well.

I agree with most of what's already been said, but I'll try to add a few things. In order of most to least significance (for me):

The standard library, especially with regard to collection methods. Want to slice/filter/sort/chunk an array/hash in some weird way? Ruby's standard library almost certainly supports it. So many amazing things are built-in across the board.

Not relying on indentation for scoping. It's one of my biggest beefs with Python. Yes, of course, code should be indented properly. But goodness....let my linter enforce that, not the interpreter. I don't love ruby's do/end keywords (I prefer curly-braces), but at least having a visual cue for end-block is a vast improvement over python.

A more consistent interface. Everything is an object, and you invoke methods on those objects. I think [].size just makes more intuitive sense than len([]).

Great readability boosts from things like question-marks or exclamation-points in method names (admittedly that felt gross and wrong at first), trailing if-statements, unless-conditionals, invoking methods without parens (though I only sanction this if not passing args).

A more helpful, less snobby community. 100% just my personal experience, maybe I've just had bad luck with pythonistas.

No __init__.py nonsense. Maybe that's fixed/improved in python3? But I hate it. In fact, I hate any use of dunders...littering the code with unreadable symbols.

🌐
The Codest
thecodest.co › blog › ruby-vs-python
The Ultimate Breakdown: Ruby vs. Python | The Codest
September 22, 2021 - Both Python and Ruby are dynamically typed languages. As a result, the programmer does not have to specify the type of variables while writing the code. Their type is determined while the program is running and it may change. The type of a variable is derived from the value stored in it.
🌐
Turing
turing.com › blog › ruby-vs-python-what-is-the-difference
Ruby vs. Python: What Is the Difference? | Turing
February 21, 2025 - Python and Ruby have a clean and readable syntax, much like English.
🌐
UpGuard
upguard.com › blog › python-vs-ruby
Ruby vs Python: Comparing Languages | UpGuard
January 9, 2025 - Python and Ruby are two of the best examples of the new generation of high-level languages which focus on simplicity and giving the programmer the ability to get things done fast, rather than syntax correctness and strict hierarchy (insert cough that sounds like “Java!” here).
🌐
Iglu
iglu.net › ruby-vs-python
Ruby vs Python: Complete Side-by-Side Comparison - Iglu.net
January 13, 2026 - Python relies on indentation to block code logic, whereas in Ruby indentation is not compulsory – but is encouraged. A focus on expressing complex logic with as little syntax as possible; this is why both languages are often described as highly ...
🌐
Ruby
ruby-lang.org › en › documentation › ruby-from-other-languages › to-ruby-from-python
To Ruby From Python | Ruby
You never directly access attributes. With Ruby, it’s all method calls. Parentheses for method calls are usually optional. There’s public, private, and protected to enforce access, instead of Python’s _voluntary_ underscore __convention__.
🌐
JayDevs
jaydevs.com › ruby-vs-python
Ruby vs. Python: Which Language Will Power Your Project in 2024? - JD
November 11, 2025 - Ruby’s flexibility and expressive syntax facilitate code experimentation but can make testing for errors more challenging. Thus, Ruby code may require additional time to debug. Python, with its readable syntax, supports writing testable code.
🌐
EDUCBA
educba.com › home › software development › software development tutorials › top differences tutorial › python vs ruby
Python vs Ruby | Top 6 Beneficial Differences You Should Know
May 6, 2023 - Guide to Python vs Ruby. Here we discussed Python vs Ruby head-to-head comparison, key differences, infographics, and comparison table.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
One Month
learn.onemonth.com › home › ruby vs. python: what’s the difference?
Ruby vs. Python: What's the Difference? - Learn to code in 30 Days!
September 30, 2022 - Notice how Python requires you to import specific functionality from datetime and dateutil libraries. It’s explicit, but that’s great because you can easily tell where everything is coming from. With the Ruby version, a lot more is hidden behind a curtain.
🌐
Medium
medium.com › @st4046641 › ruby-vs-python-is-ruby-better-than-python-b44ffea28a77
Ruby vs Python: Is Ruby Better than Python? | by Shriyansh Tiwari | Medium
November 6, 2024 - Syntax Comparison: Ruby vs Python One of the primary considerations when choosing between Python and Ruby is their syntax. Both languages prioritize clean and readable code, but they approach it in slightly different ways. Ruby’s syntax is often described as being more “expressive,” aiming to resemble natural language as closely as possible.
🌐
Quora
quora.com › Is-Ruby-a-better-designed-programming-language-than-Python-good-balance-of-OOP-functional-programming-capabilities-syntax-and-semantics-etc
Is Ruby a better designed programming language than Python (good balance of OOP/functional programming capabilities, syntax and semantics, etc.)? - Quora
Answer (1 of 4): I’m not super experienced with Ruby, so take what I say with a grain of salt, but I would say they have different strengths in terms of design—though I would say overall, I prefer the design of Ruby. The main strength of Ruby is that it is more true to the ideals of object orien...
🌐
Coursera
coursera.org › coursera articles › computer science and engineering › web and app development › ruby vs. python: which should you choose?
Ruby vs. Python: Which Should You Choose? | Coursera
February 7, 2026 - If you're unsure what you'd like ... with high developer productivity thanks to its rapid development capabilities, concise syntax, and code reusability....
🌐
Efigence
efigence.com › home › differences between python and ruby
Ruby vs Python: Differences, similarities, performance
September 3, 2024 - Python and Ruby are considered to be among the most popular scripting programming languages. Although they have much in common, they differ from each other in terms of their history, syntax, semantics, features, and performance. However, both are quite easy to learn and efficaciously used in ...
🌐
BairesDev
bairesdev.com › home › blog › software development
Which Language Is Best, Python or Ruby?
Python’s syntax emphasizes readability and clarity by following a more structured and minimalist approach. Philosophy: Ruby emphasizes developer happiness and elegance as it aims to provide a delightful programming experience.