Advertisement

Python中导入模块中的函数/变量的方式

阅读量:

1、引入模块内所有函数与变量,相关代码如下:
》生成名为say_hello.py的模块文件:

复制代码
    #file:say_hello.py
    def say_hi():
    print("hello,I'm ISmileLi!")
    
    name = 'ISmileLi'
    
    
      
      
      
      
      
    

》调用模块say_hello.py的使用方式如下:

复制代码
    #file:use_say_hello.py
    import say_hello
    
    say_hello.say_hi()
    get_name = say_hello.name
    print(get_name)
    
    
      
      
      
      
      
      
    

执行结果:

在这里插入图片描述

2、引入模块内特定的函数或变量

复制代码
    #file:use_say_hello_func_attr.py

全部评论 (0)

还没有任何评论哟~