Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

pythonÖÐÀàµÄÊôÐÔ

pythonÖÐÀàµÄÊôÐÔ
pythonÖеÄÀà½Ðclass object,ÀàµÄʵÀý½Ðinstance object.
Àà Class Objects
ÀàÓµÓÐÁ½ÖÖ²Ù×÷,1.ÀàÊôÐÔ attribute references 2.ʵÀý»¯instantiation
1.ÀàÊôÐÔ¾ÍÏ൱ÓÚרÊôÓÚÒ»¸öÀàµÄ±äÁ¿(¼´Ä³Ð©ÓïÑÔÖеÄÀàµÄ¾²Ì¬¹«¹²±äÁ¿static public),ʹÓ÷½·¨ÊÇ:ÀàÃû³Æ.ÀàÊôÐÔÃû³Æ
2.ʵÀý»¯ÔòÊÇ´´½¨Ò»¸öÀàµÄʵÀýµÄ·½·¨,ʹÓ÷½·¨ÊÇ:ÀàÃû³Æ()
ÔÚʹÓÃʵÀý»¯·½·¨ºó,½«»á´´½¨Ò»¸ö¿ÕµÄÀàʵÀý,Ò»°ãµÄpythonÀàµÄ¶¨ÒåÖлáÓÐÒ»¸öÌØÊâµÄ·½·¨À´³õʼ»¯,Õâ¸ö·½·¨¾ÍÊÇ__init__(),µ±µ÷ÓÃÁËÀàµÄʵÀý»¯·½·¨ºó,__init__()·½·¨»áÁ¢¿Ì±»Õâ¸öÀàµÄʵÀýµ÷ÓÃ.Ò²¾ÍÊÇ˵,__init__()²»Êǹ¹Ô캯Êý,¶øÊÇÒ»¸öÆÕͨµÄ·½·¨.
ÀàµÄʵÀý Instance Objects
ÀàµÄʵÀýÖ»ÓµÓÐÒ»ÖÖ²Ù×÷,Õâ¾ÍÊÇ 1.ÊôÐÔµ÷Óà attribute references.
ÊôÐÔµ÷ÓÃÖ¸ 1.Êý¾ÝÊôÐÔ 2.·½·¨
Êý¾ÝÊôÐÔ
Êý¾ÝÊôÐÔ²»ÐèÒªÔ¤Ïȶ¨Òå!µ±Êý¾ÝÊôÐÔ³õ´Î±»Ê¹ÓÃʱ,Ëü¼´±»´´½¨²¢¸³Öµ(they spring into existence when they are first assigned to) ¿´ÏÂÃæµÄÀý×Ó
>>> class test:
...  pass
...  t=test()
...  t.name='notus'
...  print t.name
...
notus
ÎÒÃÇÔÚÀàTestÖв¢Ã»Óж¨ÒånameÕâ¸öÊý¾ÝÊôÐÔ,µ«ÊÇÔÚ´úÂëÖÐÈ´¿ÉÒÔÖ±½ÓʹÓÃ,Õâ¾ÍÊÇÊý¾ÝÊôÐÔ.
ÈçºÎ¶¨ÒåÀàµÄÊôÐÔ
ÏÖÔÚ,Å׿ª¹ãÒåÉ϶ÔÊôÐÔattributeµÄ½âÊÍ,ÔÚʵ¼Ê±à³ÌÖо­³£ÓõÄÊôÐÔÕâ¸ö´Ê,ÔÚpythonµÄclassÖÐÓÐÁ½ÖÖÊôÐÔ:ÀàÊôÐÔ,Êý¾ÝÊôÐÔ.(´ó¶àÊý±à³ÌÓïÑÔ¶¼ÓÐÕâÑùÁ½ÖÖÊôÐÔ).ÀàÊôÐÔÊôÓÚÀà,Êý¾ÝÊôÐÔÊôÓÚÀàµÄʵÀý.ÎÒÃǼÙÉèÓÐÀàTest,ÔòÒ»°ãÕâÁ½ÖÖÊôÐÔµÄÓ÷¨ÊÇ
>>> class test:
...  pass
...  t=test()
...  t.name='notus'
...  print t.name
...  test.mode='auto'
...  print test.mode
...
notus
auto
Êý¾ÝÊôÐÔnameºÍÀàÊôÐÔmode¾ùûÓÐÔÚÀàÖб»¶¨Òå,ÄãÒª×öµÄ,Ö»ÊÇÔÚÐèÒªµÄʱºòʹÓÃËûÃǼ´¿É.
Æäʵ´ó¼Ò¿´µ½ÀàÊôÐÔºÍÊý¾ÝÊôÐÔµÄ×îÖ±¹ÛµÄÇø±ðÊÇÊý¾ÝÊôÐÔ£¨¶¨ÒåµÄÀàʵÀý£¬ÀàµÄʵÀý»¯£©Ê¹Ó÷½·¨ÊÇ:ÀàÃû³Æ()——t=test()£¬ÀàÊôÐÔÀàÃû³Æ.ÀàÊôÐÔÃû³Ætest.mode¡£
ÈçºÎÔ¤ÏȸøÊôÐÔ¸³Öµ
class Test:
def ask(theInstance):
       theInstance.name='notus'
       Test.mode='auto'
##print Test.mode
t=Test()
##print t.name
t.ask()
print Test.mode
print t.name
ÀàTestÓз½·¨ask.×¢Òâ¿´³ÌÐòÖб»×¢Ê͵ôµÄ


Ïà¹ØÎĵµ£º

PythonºÍRubyµÄ¶Ô±È£¬¾ÀÕýһЩÎó½â

PythonºÍRubyµÄ¶Ô±È£¬¾ÀÕýһЩÎó½â
ÏÂÃæÊÇÎÒÔÚ¿´Á½Æª¹ØÓÚPythonºÍRuby¶Ô±ÈµÄÎÄÕÂʱ£¬Ëù×÷µÄ¾ÀÕý£¬Ô­ÎͼÊǹ㷺Á÷Ðеģ¬±È½ÏºÃÕÒ¡£
------------------------------------------------------
¡¶rubyºÍpythonµÄ±È½Ï¡·¸üÕýÒ»µãÊÂÇé
1¡¢Îĵµ¡¢¿ªÔ´ÏîÄ¿¡¢¿âÖ§³Ö£¬ÕâЩ¶«Î÷Ruby²»Òª¸úPython±È£¬²»ÊǼ¸¸öÊýÁ¿¼¶µÄÎÊÌ⣬ºÎ±ØÃ²Ë ......

Python ÓÎÏ·³õѧ

import sys, pygame, time
size = width, height = 700,700
fontColor = (0,0,255)
class walk:
'''This is a game about war.
Just like war 3.'''
def __init__(self):
'''Init the screen.
Get param and init the screen'''

#print ('this is init funnction') ......

¡¾zz¡¿Python³£ÓÃ×ÊÔ´ÍøÖ·

zz from ¡¶¿É°®µÄPython¡·
http://www.woodpecker.org.cn/
Python±ê×¼¿â http://www.woodpecker.org.cn:9081/doc/Python/_html/PythonStandardLib/
¼òÃ÷Python½Ì³Ì http://www.woodpecker.org.cn:9081/doc/abyteofpython_cn/chinese/index.html
Python¿ìËÙ½éÉÜ http://www.zoomquiet.org/share/s5/intropy/070322-intro ......

python Ö® pilÉú³ÉÑéÖ¤ÂëͼƬ

#!/usr/bin/python
#coding=utf-8
import Image,ImageDraw,ImageFont,os,string,random,ImageFilter
def initChars():
"""
ÔÊÐíµÄ×Ö·û¼¯ºÏ£¬³õʼ¼¯ºÏΪÊý×Ö¡¢´óСд×Öĸ
usage: initChars()
param: None
return: list
·µ»ØÔÊÐíµÄ×Ö·û¼¯ºÍ
for: picCheckerÀà³õʼ×Ö·û¼¯ºÏ
todo: ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ