list to tuple and vice versa

StarWing weasley_wx at sina.com
Sun Oct 18 01:08:54 EDT 2009


On 10月18日, 下午12时19分, Ben Finney <ben+pyt... at benfinney.id.au> wrote:
> Jabba Laci <jabba.l... at gmail.com> writes:
> > Right, it was my bad. After removal the tuple() function works
> > perfectly.
>
> Note that, though it is callable, ‘tuple’ is not a function but a type:
>
>     >>> tuple
>     <type 'tuple'>
>     >>> len
>     <built-in function len>
>
> You can use the built-in ‘type’ type to get the type of any object:
>
>     >>> foo = 12
>     >>> type(foo)
>     <type 'int'>
>     >>> bar = 1, 2, 3
>     >>> type(bar)
>     <type 'tuple'>
>     >>> type(tuple)
>     <type 'type'>
>     >>> type(len)
>     <type 'builtin_function_or_method'>
>     >>> type(type)
>     <type 'type'>
>
> --
>  \      “Pinky, are you pondering what I'm pondering?” “Uh, I think so |
>   `\  Brain, but this time, you wear the tutu.” —_Pinky and The Brain_ |
> _o__)                                                                  |
> Ben Finney

A type is always callable. call a type will call its __init__ special
method (or and __new__ special method together).



More information about the Python-list mailing list