Scope: variable, function
public (public): can be directly referenced, such as: ABC, PI, test (), similar to __xxx__ such a special variable. Lenovo : In the C language, when something in the module wants to be referenced externally, it is preceded by an extern, or it can be added without extern
private (Secret): should not be directly quoted, such as: _xxx/__xxx variables such as Lenovo: In C, when something in the module does not want to be referenced externally, the static
is added in front of it.
What do I do when there are variables or functions in a module that you do not want to be referenced by others? As follows:
Private.py is the modulated module
public.py is a public module
#private.py
#!/usr/bin/env Python3
#-*-Coding:utf-8-*-
def _private_1 (name): #该函数为秘密函数
return ' Hello,%s '% name
def _private_2 (name): #该函数为秘密函数
return ' Hi,%s '% name
def greeting (name= "): #该函数为公开函数, can be called
if Len (name) > 3:
& nbsp; return _private_1 (name)
else:
return _private_2 (name)
If __name__== ' __main__ ':
Print (greeting ())
#public. py
#!/usr/bin/env Python3
#-*-Coding:utf-8-*-
From private import greeting #导入private模块的greeting函数
Print (Greeting ([' You ', ' very ', ' nice '))
Scope of the Python module