Hacker News new | past | comments | ask | show | jobs | submit login

I stand corrected. However, I do think that in order to use this like I want ...

map(str.capitalize, ['a', 'b', 'c'])

... you have to understand far too much of Python's implementation (for example, that str is not a function, but a class that kindof acts like a function) to program. I still think that methods + functions = a pain point in Python.




Well... to make it easier you can think of classes as normal functions returning instances. For almost any practical purpose, that's true. Also, str.capitalize is (for any practical purpose again :) ) a one-argument function that takes a string and returns a capitalised string.


In Python, str is a class. And all classes act as function. If there is ever any doubt, you can tell like this:

    >>> type(str)
    <type 'type'>
You can tell that str is a class because it inherits from type type.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: