Variables can be private which can be useful on many occasions. A private variable can only be changed within a class method and not outside of the class.

Objects can hold crucial data for your application and you do not want that data to be changeable from anywhere in the code.

class Car:

    __maxspeed = 0
__name = "" def __init__(self):
self.__maxspeed = 200
self.__name = "Supercar" def drive(self):
print 'driving. maxspeed ' + str(self.__maxspeed) redcar = Car()
redcar.drive()
redcar.__maxspeed = 10 # will not change variable because its private
redcar.drive()

If you want to change the value of a private variable, a setter method is used. This is simply a method that sets the value of a private variable.

最新文章

  1. MongoDB replica set IDs do not match
  2. Asp.net中文件的压缩与解压
  3. JAVA并发编程
  4. 【wikioi】1034 家园(最大流+特殊的技巧)
  5. ssh tunnel通道
  6. HtmlParser
  7. ListView中使用type需要注意的东西
  8. LVS三种模式配置及优点缺点比较 转
  9. Chatwin商务通
  10. Android源代码之Gallery专题研究(2)
  11. NET WEB
  12. Visual Studio 2013 的 Browser Link 功能
  13. Apache2.4 137行 httpd-ahssl.conf
  14. PAT (Advanced Level) 1091. Acute Stroke (30)
  15. UML类图基本画法
  16. 第二次项目冲刺(Beta阶段)--第六天
  17. [数据结构] 快速排序C语言程序
  18. css3的transform-origin配合scale,控制动画,实现各种hover效果
  19. Network Principle Course Summary 001
  20. uva-10004-俩色图验证

热门文章

  1. golang error (slice of unaddressable value)
  2. 【SQL系列】深入浅出数据仓库中SQL性能优化之Hive篇
  3. Java多线程学习——图片下载
  4. 【Linux开发】CCS远程调试ARM,AM4378
  5. python+selenium下弹窗alter对象处理01
  6. 右击main 方法运行正常,启动tomcat 后,spring boot 项目 出现参数字符串是乱码的情况
  7. Tomcat进程、SFTP服务器
  8. CentOS7设置hostname、hosts、静态IP地址、关闭防火墙
  9. MySQL服务意外停止
  10. java虚拟机学习总结之GC回收算法与GC收集器