I’m taking a Data Science course that incorporates Python. I thought I’d write a quick + dirty summary of some key (cool) differences between the two languages. Forgive me if the syntax is slightly off as I’m writing this from memory.
Python and Ruby both use the method declaration
def, but Python also uses
(): at the end of the declaration. In Ruby, the parens are optional. In Python, the parens and colons are required. Python also requires colons for for loops and if/else statements.
Python does not need the
end keyword to signify the end of a method block. Python relies on whitespace and indentation to signify the end of a block of code.
In Ruby, methods return the last line of code that is evaluated. In Python, you must be explicit and use
In Ruby, a collection that uses index is called an Array. Python calls them lists.
In Ruby, a collection of key/value pairs is called a Hash. Python calls them Dictionaries.
Ruby uses the
initialize method to instatiate new instances of a class. Python uses
In Python, you must pass in the keyword
self as the first argument in a method. In Ruby, you can assign a method to self as in
|| for comparisons. Python uses the keywords
Whitespace and colons
…to be continued