• 技术文章 >Python技术 >Python基础教程

    Python中三种模块类型的介绍

    小妮浅浅小妮浅浅2021-08-26 09:39:22原创4170

    1、内置标准模块,又称为标准库。

    如 sys、time、math、json 模块等。内置 Python 模块一般都位于安装目录下 Lib 文件夹中。

    2、第三方开源模块。这类模块一般通过pip install模块名进行在线安装。

    如果 pip 安装失败,也可以直接访问模块所在官网下载安装包,在本地离线安装。

    3、自定义模块。

    由开发者自己开发的模块,方便在其他程序或脚本中使用。

    实例

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    #!/usr/bin/env python3

    # -*- coding: utf-8 -*-

      

    ' a test module '

      

    __author__ = 'Michael Liao'

      

    import sys

      

    def test():

        args = sys.argv   # argv参数用列表存储命令行的所有参数

        if len(args)==1:  # 当列表长度为1时即只有一个参数时

            print('Hello, world!')

        elif len(args)==2: # 当命令行有两个参数时

            print('Hello, %s!' % args[1])

        else:

            print('Too many arguments!')

      

    if __name__=='__main__':

        test()

    以上就是Python中三种模块类型的介绍,希望对大家有所帮助。更多Python学习指路:python基础教程

    本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

    专题推荐:python 模块
    上一篇:Python中OSI七层模型是什么 下一篇:Python继承的原理分析

    相关文章推荐

    • python center()如何填充字符串• python isdigit如何判断字符串• python isidentifier()方法是什么• python中isnumeric如何使用• python中isprintable判断字符的使用• python中有哪些大小写转换方法• python partition如何分割字符串• splitlines在python中返回列表• python copy()和直接赋值的区别• python get获取指定键值• python in操作符是什么• python中popitem如何使用• python中update更新字典的方法• python计算集合交集的符号• python集合的并集操作• python集合的差集如何计算• python判断两个集合是否相等• python如何判断集合的超集• python防止栈溢出的解决• python有哪些切片类型

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网