python中all函数的使用方法

小编给大家分享一下python中all函数的使用方法,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

语法

all(iterable)

只采用一个参数

any函数一样,iterable-包含元素的任何可迭代

实例内容:Python代码文件test.py如下

def _local_func():
    print 'local'
def test():
_local_func()

通过all函数来控制import *的导出范围

__all__ = ['test']
def _local_func():
    print 'local'
def test():
_local_func()
def test1():
_local_func()

执行结果如下:

>>> from test import *
>>> test1()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'test1' is not defined
>>> test()
local
>>>

以上是“python中all函数的使用方法”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!