博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
chap Class
阅读量:5098 次
发布时间:2019-06-13

本文共 1209 字,大约阅读时间需要 4 分钟。

>>> john = AddrBookEntry('John Doe', '408-555-1212')Created instance for: John Doe>>> jane = AddrBookEntry('Jane Doe', '650-555-1212')Created instance for: Jane Doe

 

Class MyData(object):    pass>>> class MyData(object):...   pass...>>> mathObj = MyData()>>> mathObj.x = 4>>> mathObj.y = 5>>> mathObj.x + mathObj.y9

  

"x" and "y" belong to the mathObj, the mathObj act as a container.

Not of class MyData


 

self is like the C++ this key word.

this is the python philosophy, everything declared explicitly


 

__init__() is like the constructor

Python creates the instance for you and then calls __init__() during instantiation

to define additional behavior that should occur when a class is instanciated.

classAddrBookEntry(object): # class definition    'address book entry class'    def __init__(self, nm, ph): # define constructor        self.name = nm # set name        self.phone = ph # set phone#        print'Created instance for:', self.name    def updatePhone(self, newph): # define method        self.phone = newph        print'Updated phone# for:', self.nam

  

The only initialize the parameter is the name and phone that is --nm --ph

 

 

 

转载于:https://www.cnblogs.com/geometry-/archive/2012/06/28/2568737.html

你可能感兴趣的文章
剑指offer系列32-----对称二叉树的判断
查看>>
Silverlight实用窍门系列:19.Silverlight调用webservice上传多个文件【附带源码实例】...
查看>>
2016.3.31考试心得
查看>>
Laravel-redis-订阅发布
查看>>
Weka SMO
查看>>
codeforces305A
查看>>
java服务器热部署的原理
查看>>
js精确计算
查看>>
oc __weak和__strong的区别
查看>>
Unitils+hibernate+Spring+PostgreSql做dao层测试遇到的错误
查看>>
Eclipse怎么样添加智能感知提示功能(含Windows版和Mac版)
查看>>
搜索引擎与开发
查看>>
CRM2011 linq 查询
查看>>
13个小技巧帮你征服Xcode
查看>>
PowerShell基础
查看>>
linux操作技巧
查看>>
Redis文章链接
查看>>
Spring MVC中<mvc:annotation-driven />和<context:annotation-config />的区别分析
查看>>
如何拿CSDN博客上的原图
查看>>
Spring Boot集成Spring Data Reids和Spring Session实现Session共享
查看>>