Ⅰ python中的常用内置函数有哪些呢
abs() divmod() input() open() staticmethod()
all() enumerate() int() ord() str()
any() eval() isinstance() pow() sum()
basestring() execfile() issubclass() print() super()
bin() file() iter() property() tuple()
bool() filter() len() range() type()
bytearray() float() list() raw_input() unichr()
callable() format() locals() rece() unicode()
chr() frozenset() long() reload() vars()
classmethod() getattr() map() repr() xrange()
cmp() globals() max() reverse() zip()
compile() hasattr() memoryview() round() __import__()
complex() hash() min() set()
delattr() help() next() setattr()
dict() hex() object() slice()
dir() id() oct() sorted()
Ⅱ 在Python中怎么把class类转成list类
你需要自定义函数。
或者使用__list__,这样就可以使用内置的list函数了。
classA:
def__init__():
self.a=1
self.b=2
defto_list():
"""需要你自定义函数行为"""
return[self.a,self.b]
def__list__():
"""需要你自定义函数行为"""
return[self.a,self.b]
a=A()
lst1=a.to_list()
lst2=list(a)#调用__list__
别的可以直接调用list函数的都是底层实现了__list__或者做了别的实现,你自己的类需要你自己实现。