美文网首页
python标准库 _ _builtin_ _ 模块

python标准库 _ _builtin_ _ 模块

作者: qqhai | 来源:发表于2018-07-06 13:25 被阅读0次

这个模块包含 Python 中使用的内建函数. 一般不用手动导入这个模块;

Python 会帮你做好一切.


使用元组或字典中的参数调用函数  apply函数

apply函数和scala的apply函数功能类似

File: builtin-apply-example-1.py

def function(a, b):

    print a, b

apply(function, ("whither", "canada?"))

apply(function, (1, 2 + 3))

#whither canada? 1 5


File: builtin-apply-example-2.py

def function(a, b):

    print a, b

apply(function, ("crunchy", "frog"))

apply(function, ("crunchy",), {"b": "frog"})

apply(function, (), {"a": "crunchy", "b": "frog"})


crunchy frog

crunchy frog

crunchy frog


使用 apply 函数调用基类的构造函数

File: builtin-apply-example-3.py

class Rectangle:

    def _ _init_ _(self, color="white", width=10, height=10):

        print "create a", color, self, "sized", width, "x", height

class RoundedRectangle(Rectangle):

    def _ _init_ _(self, **kw):

        apply(Rectangle._ _init_ _, (self,), kw)

rect = Rectangle(color="green", height=100, width=100)

rect= RoundedRectangle(color="blue",height =20)


如果你写过较庞大的 Python 程序, 那么你就应该知道 import 语句是用来导

入外部模块的 (当然也可以使用 from-import 版本). 不过你可能不知道

import 其实是靠调用内建函数 _ _import_ _ 来工作的.

p15

相关文章

  • python标准库 _ _builtin_ _ 模块

    这个模块包含 Python 中使用的内建函数. 一般不用手动导入这个模块; Python 会帮你做好一切. 使用元...

  • Udacity Python 随笔 *

    Udacity Python入门 标准库推荐 Python 标准库的模块很多!为了帮助大家熟悉可用模块,以下是精选...

  • (三)python常用标准库

    python常用标准库 python标准库常见模块 操作系统相关:os 时间与日期:time、datetime 科...

  • 每周一个 Python 模块 | itertools

    系列文章列表:每周一个 Python 模块 | functools Python 标准库模块 itertools ...

  • Python 中引入一个文件,模块的概念

    Python 提供了强大的模块支持,主要体现在,不仅 Python 标准库中包含了大量的模块(称为标准模块),还有...

  • python模块logging学习

    Logging模块的作用 从Python2.3起,Python的标准库加入了logging模块.logging模块...

  • Python入门:模块

    十一、模块 Python有一个标准库(不需要pip安装),里面涉及了很多内置模块Python标准库(中文版):ht...

  • python之模块之碎碎念

    import语句导入的模块顺序 1、Python标准库模块 2、python第三方库模块 3、应用程序自定义模块 ...

  • Python 标准库

    很好的python标准库资源网站https://pymotw.com/3/ Python标准库 是一组模块, 安装...

  • python3从零学习-5.0、标准库

    Python 标准库 Python 标准库非常庞大,所提供的组件涉及范围十分广泛。这个库包含了多个内置模块 (...

网友评论

      本文标题:python标准库 _ _builtin_ _ 模块

      本文链接:https://www.haomeiwen.com/subject/znivuftx.html