2024-09-30 14:26:28 发布
网友
python中是否有与PHP list()函数等效的函数?例如:
菲律宾比索:
list($first, $second, $third) = $myIndexArray; echo "First: $first, Second: $second";
>>> a, b, c = [1, 2, 3] >>> print a, b, c 1 2 3
直接或直接翻译:
Python通过调用右侧表达式上的__iter__方法并将每个项分配给左侧的变量来实现此功能。这允许您定义如何将自定义对象解压为多变量赋值:
__iter__
>>> class MyClass(object): ... def __iter__(self): ... return iter([1, 2, 3]) ... >>> a, b, c = MyClass() >>> print a, b, c 1 2 3
直接或直接翻译:
^{pr2}$Python通过调用右侧表达式上的
__iter__
方法并将每个项分配给左侧的变量来实现此功能。这允许您定义如何将自定义对象解压为多变量赋值:相关问题 更多 >
编程相关推荐