zoukankan      html  css  js  c++  java
  • python模块之间的代码元素的访问

    1.一个模块本质就是一个文件,在模块中封装了很多代码元素。

    1)导入所有内容:import语句

    2)只导入一个元素,from import

    3)如果名称有冲突 from import as

    # @File    : world.py
    # @Software: PyCharm
    #coding=utf-8

    x='你好'
    y=True
    z=20.0

    # @File    : hello.py
    # @Software: PyCharm
    #coding=utf-8
    from test_module import world
    from test_module.world import x as x2
    from test_module.world import z
    x=100
    y=20
    print(y) #访问当前模块变量y
    print(world.y)#访问world模块变量y
    print(z)#访问world模块变量z
    print(x2) #x2是world模块x别名

  • 相关阅读:
    Java 概述
    vue组件事件
    小程序注册
    小程序基础知识梳理
    小程序简介
    公众号
    jeecg-boot
    小程序背景图
    bootstrap-select采坑
    存取cookie
  • 原文地址:https://www.cnblogs.com/JacquelineQA/p/13171993.html
Copyright © 2011-2022 走看看