underline.py
__all__ = ['_underline_variable', '__underline_variable', '_underline_func',
'__underline_func', '_underline_class', '__underline_class'] _underline_variable = 100
__underline_variable = 200 def _underline_func():
pass def __underline_func():
pass class _underline_class():
pass class __underline_class():
pass class Base():
def _underline(self):
pass def __underline(self): # 私有
pass class Derived(Base):
pass if __name__ == '__main__':
base = Base()
base._underline()
#base.__underline()
base._Base__underline() derived = Derived()
derived._underline()
#derived._Derived__underline()
derived._Base__underline()
 test.py
# 1 用import方式导入
import underline print(underline._underline_variable)
print(underline.__underline_variable)
underline._underline_func()
underline.__underline_func()
test1 = underline._underline_class()
test2 = underline.__underline_class() print('*' * 20) # 2 没有定义__all__属性,用from ... import *方式导入
#from underline import *
#print(_underline_variable)
#print(__underline_variable)
#_underline_func()
#__underline_func()
#test1 = _underline_class()
#test2 = __underline_class() # 3 定义__all__属性,用from ... import *方式导入
from underline import *
print(_underline_variable)
print(__underline_variable)
_underline_func()
__underline_func()
test1 = _underline_class()
test2 = __underline_class()

python 单下划线和双下划线的更多相关文章

  1. python 里面的单下划线与双下划线的区别

    python 里面的单下划线与双下划线的区别 Python 用下划线作为变量前缀和后缀指定特殊变量. _xxx 不能用'from moduleimport *'导入 __xxx__ 系统定义名字 __ ...

  2. Python里的单下划线,双下划线,以及前后都带下划线的意义

    Python里的单下划线,双下划线,以及前后都带下划线的意义: 单下划线如:_name 意思是:不能通过from modules import * 导入,如需导入需要:from modules imp ...

  3. python单下划线、双下划线、头尾双下划线说明:

      单下划线.双下划线.头尾双下划线说明: __foo__: 定义的是特殊方法,一般是系统定义名字 ,类似 __init__() 之类的. _foo: 以单下划线开头的表示的是 protected 类 ...

  4. 测试Python类成员的单下划线,双下划线,两头下划线的区别

    首先原谅一个菜鸟叫他“两头下划线”.记得在windows编程中,很多宏定义使用下划线+大写,给人逼格很高的错觉.对于Python下划线的认识,大概是从__dict__这个属性开始的,看__dict__ ...

  5. Python笔记_第三篇_面向对象_4.单下划线和双下划线

    说道这里我们需要稍微暂停一下.前面我们说到了类是作为一个对象存放容器.这个容器里面有属性和方法.最好的理解类的方式就是把类想想成一个容器. 然后构造了一个析构函数和构造函数,然后又对object和se ...

  6. python(七) Python中单下划线和双下划线

    Python中单下划线和双下划线: 一.分类 (1).以单下划线开头,表示这是一个保护成员,只有类对象和子类对象自己能访问到这些变量. 以单下划线开头的变量和函数被默认是内部函数,使用from mod ...

  7. python中的单下划线和双下划线意义和作用

    Python中并没有真正意义上的“私有”,类的属性的的可见性取决于属性的名字(这里的属性包括了函数).例如,以单下划线开头的属性(例如_spam),应被当成API中非公有的部分(但是注意,它们仍然可以 ...

  8. python单下划线与双下划线的区别

    Python 用下划线作为变量前缀和后缀指定特殊变量. _xxx 不能用'from moduleimport *'导入 __xxx__ 系统定义名字 __xxx 类中的私有变量名 核心风格:避免用下划 ...

  9. python类中方法加单下划线、双下划线、前后双下滑线的区别

    首先看一段代码: class Foo(): def __init__(self): print "__init__ method" def public_method(self): ...

  10. 【python】单下划线与双下划线的区别

    Python 用下划线作为变量前缀和后缀指定特殊变量. _xxx 不能用'from moduleimport *'导入 __xxx__ 系统定义名字 __xxx 类中的私有变量名 以单下划线开头(_f ...

随机推荐

  1. huawei校招测试题

    三道题两小时. 第一题,圈住所有点的长方形,很简单略过. 第二题:奇偶排序. 奇偶排序 描述: 输入若干(不超过1000个)非负整数数字,请先取出为奇数的数字按从大到小排序,再取出偶数从小到大进行排序 ...

  2. LOJ#139. 树链剖分

    LOJ#139. 树链剖分 题目描述 这是一道模板题. 给定一棵$n$个节点的树,初始时该树的根为 1 号节点,每个节点有一个给定的权值.下面依次进行 m 个操作,操作分为如下五种类型: 换根:将一个 ...

  3. jquery1.9是最后支持IE678

    bootstrap  需要 jquery 1.9.1或更高 jquery1.9是最后支持IE678

  4. Linux时间子系统之(一):时间的基本概念【转】

    本文转载自:http://www.wowotech.net/timer_subsystem/time_concept.html 本文使用Q & A的方式来和大家以前探讨一下时间的基本概念 一. ...

  5. chdir函数的使用【学习笔记】

    #include "apue.h" #include <fcntl.h> int main(void) { ) err_sys("chdir failed&q ...

  6. POJ3074 Sudoku —— Dancing Links 精确覆盖

    题目链接:http://poj.org/problem?id=3074 Sudoku Time Limit: 1000MS   Memory Limit: 65536K Total Submissio ...

  7. 启动tomcat时,经常遇到的问题 8080 端口被占用

    启动tomcat失败时,弹出的窗口如上,说明8080被某个进程占用了 需要把占用8080端口的进程给kill掉 Win+R 输入运行cmd 打开命令提示符cmd.exe netstat -ano|fi ...

  8. String bulit-in function

    tip: 和tuple一样,字符串也是不可变的类型,字符串的内建函数有非常多,我们一一举例来看看他们的作用 下面是用dir(str) 输出的内容: ['__add__', '__class__', ' ...

  9. python二维数组初始化

    >>> a=[[0]*3 for i in range(3)]>>> a[[0, 0, 0], [0, 0, 0], [0, 0, 0]]>>> ...

  10. [Selenium] Grid 介绍

    Selenium Grid 支持分布式测试,使测试人员可在分布式环境中进行测试 一般而言,在面临以下情况时可考虑使用Selenium Grid : 1.测试多个浏览器或单个浏览器多个版本,或测试不同操 ...