Why python objects?

why almost everything in python is an object ? what was the reason behind this design

It’s a good question, and Noyad had done a good reply.

I think that another good reason is that every object has a refcount, so it’s simple to garbage collect.

I’m not Guido, but maybe he chose this design because it’s powerful, simple and beautiful.

Another good question is: why not? :wink:

Gudio wrote a little blog post some time ago, you may find it interesting: The History of Python: First-class Everything

curious onto why things like loops and conditions aren’t object too.
thanks for linking the blog

Well, iterators are objects too.

The for loop itself could have been an object method and this is exactly what some languages like Ruby, Javascript, Smalltalk and Lua do.

For instance, in ruby one could write something like:

seq.each {|x| print(x)}

Python didn’t. Not sure why. Perhaps because it makes keywords like break and continue a little bit harder to implement. It also doesn’t have a very convenient block/lambda syntax.

They are, actually, as statements and expressions. Conditions are expressions that evaluate to an object with a boolean value, which is nearly all objects. Loops are statements.

Code text can be represented as a string, which is an object. Appropriate code strings can be passed to functions, including eval and exec. They can also be passed to compile to convert them to code objects, which can also be passed to eval or exec or processed in other ways. Code text can also be wrapped in def statements and compiled to functions, which can be called and introspected.