Monday, October 22, 2012

Not so OO like features in Python

Python is built on Object Oriented paradigm. However, some of the python's features are not so Object Oriented to confuse OO users. For example, when converting string to intger, python doesn't provide something like "32".to_i(). Compared to Ruby that everything is an object, it looks like less OO way.
# Ruby
x = "102".to_i
# Python
x = int("102"))
Likewise, when you want to get the length, you should call the len() method explicitly.
# Ruby
x = "hello".length
# Python
x = len("hello") 
Sometimes it's annoying.

No comments:

Post a Comment