Python±Ê¼Ç£¨8£©
PythonµÄÃæÏò¶ÔÏóÐÔÖÊ
ÀàºÍ¶ÔÏóÊÇÃæÏò¶ÔÏó±à³ÌµÄÁ½¸öÖ÷Òª·½Ãæ¡£Àà´´½¨Ò»¸öÐÂÀàÐÍ£¬¶ø¶ÔÏóÕâ¸öÀàµÄ ʵÀý ¡£ÕâÀàËÆÓÚÄãÓÐÒ»¸öintÀàÐ͵ıäÁ¿£¬Õâ´æ´¢ÕûÊýµÄ±äÁ¿ÊÇintÀàµÄʵÀý£¨¶ÔÏ󣩡£
ÐèҪעÒâµÄÊÇ£¬ÔÚPythonÖУ¬¼´±ãÊÇÕûÊýÒ²±»×÷Ϊ¶ÔÏó£¨ÊôÓÚintÀࣩ¡£ÕâºÍC++¡¢Java£¨1.5°æÖ®Ç°£©°ÑÕûÊý´¿´â×÷ΪÀàÐÍÊDz»Í¬µÄ¡£Í¨¹ýhelp(int)Á˽â¸ü¶àÕâ¸öÀàµÄÏêÇé¡£
¶ÔÏó¿ÉÒÔʹÓÃÆÕͨµÄÊôÓÚ¶ÔÏóµÄ±äÁ¿´æ´¢Êý¾Ý¡£ÊôÓÚÒ»¸ö¶ÔÏó»òÀàµÄ±äÁ¿±»³ÆÎªÓò¡£¶ÔÏóÒ²¿ÉÒÔʹÓÃÊôÓÚÀàµÄº¯ÊýÀ´¾ßÓй¦ÄÜ¡£ÕâÑùµÄº¯Êý±»³ÆÎªÀàµÄ·½·¨¡£ÕâЩÊõÓï°ïÖúÎÒÃǰÑËüÃÇÓë¹ÂÁ¢µÄº¯ÊýºÍ±äÁ¿Çø·Ö¿ªÀ´¡£ÓòºÍ·½·¨¿ÉÒԺϳÆÎªÀàµÄÊôÐÔ¡£
Ò».PythonµÄ__init__·½·¨
ÀýÈç:
#!/usr/bin/python
# Filename: class_init.py
class Person:
def __init__(self, name):
self.name = name
def sayHi(self):
print 'Hello, my name is', self.name
p = Person('Swaroop')
p.sayHi()
# This short example can also be written as Person('Swaroop').sayHi()
Êä³öΪ:
$ python class_init.py
Hello, my name is Swaroop
ÔÚÒ»¶¨³Ì¶ÈÉÏ£¬¿ÉÒÔÈ϶¨ÎªPythonÖеĹ¹Ô캯Êý¡£
Èçͬ__init__·½·¨Ò»Ñù£¬»¹ÓÐÒ»¸öÌØÊâµÄ·½·¨__del__£¬ÀàËÆÓÚÎö¹¹º¯Êý.
×¢Òâ:PythonÖÐËùÓеÄÀà³ÉÔ±£¨°üÀ¨Êý¾Ý³ÉÔ±£©¶¼Êǹ«¹²µÄ£¬ËùÓеķ½·¨¶¼ÊÇÓÐЧµÄ¡£
Ö»ÓÐÒ»¸öÀýÍ⣺Èç¹ûÄãʹÓõÄÊý¾Ý³ÉÔ±Ãû³ÆÒÔ Ë«Ï»®Ïßǰ׺ ±ÈÈç__privatevar£¬PythonµÄÃû³Æ¹ÜÀíÌåϵ»áÓÐЧµØ°ÑËü×÷Ϊ˽ÓбäÁ¿¡£
ÕâÑù¾ÍÓÐÒ»¸ö¹ßÀý£¬Èç¹ûij¸ö±äÁ¿Ö»ÏëÔÚÀà»ò¶ÔÏóÖÐʹÓ㬾ÍÓ¦¸ÃÒÔµ¥Ï»®Ïßǰ׺¡£¶øÆäËûµÄÃû³Æ¶¼½«×÷Ϊ¹«¹²µÄ£¬¿ÉÒÔ±»ÆäËûÀà/¶ÔÏóʹÓ᣼ÇסÕâÖ»ÊÇÒ»¸ö¹ßÀý£¬²¢²»ÊÇPythonËùÒªÇóµÄ£¨Óë˫ϻ®Ïßǰ׺²»Í¬£©¡£
¶þ.ÀàµÄ¼Ì³Ð
#!/usr/bin/python
# Filename: inherit.py
class SchoolMember:
'''Represents any school member.'''
def __init__(self, name, age):
self.name = name
self.age = age
print '(Initialized SchoolMember: %s)' % self.name
def tell(self):
'''Tell my details.'''
print 'Name:"%s" Age:"%s"' % (self.name, self.age),
class Teacher(SchoolMember):
'''Represents a teacher.'''
def __init__(self, name, age, salary):
Sc
Ïà¹ØÎĵµ£º
¹¤ÓûÉÆÆäʱØÏÈÀûÆäÆ÷£¡
¿ª·¢PythonÓÃʲô¹¤¾ßºÃÄØ£¿Æäʵ¸ÕѧPythonµÄ»°£¬Ê¹ÓÃIDLE¾Í¹»ÁË£¬ËäÈ»µ÷ÊÔ²»ÊÇÌØ±ð·½±ã£¬µ«ÊǶÔÓÚ³õѧÒѾ¹»ÁË£¬¿ÉÒÔʹÓÃPrint½øÐмòµ¥µÄµ÷ÊÔ£¬²»½¨ÒéʹÓüÇʱ¾½øÐпª·¢£¬²»ÖªµÀµÄÈÏΪÄãºÜÅ££¬ÖªµÀµÄ……ÕâÊÇ×Ô¼º¸ø×Ô¼ºÕÒ×ïÊÜ£¬ÓÃEditplusÃ²Ë ......
¶þ½øÖÆÎļþÏÂÔØµØÖ·£º
SinaGetBook
Ч¹ûÈçͼ£º
´úÂ룺
#!/usr/bin/env python
#coding=utf-8
#!/usr/bin/env python
#coding=utf-8
import traceback
import sys
import wx
import re
import urllib
import wx.richtext as rt
import wx.lib.buttonpanel as bp
import Casing
import Debug
def trace_back ......
¸Õ¸ÕдÍêPythonǶÈ벿·ÖµÄ¼òµ¥Àý×Ó£¨²î²»¶à¹»ÏÖÔÚÓõÄÀ²~£©£¬½Ó×Å¿´µãʵ¼ÊµÄ¶«Î÷£¬Èç¹ûûÓÐÕâЩӦÓõϰ£¬Ç°ÃæµÄǶÈëҲûÓÐʲôÒâÒ塣ǶÈëµÄÆäËû²¿·ÖÒÔºóÓöµ½ÔÙд£¬²»±ØÒ»ÏÂ×Ó°ÑÄÇЩº¯Êý¶¼Åª¶®£¬ÊǰÉ~
OK£¬À´¿´Python¿âÖÐÎÒÈÏΪ×îºÃÍæµÄÒ»²¿·Ö£¬Ò²¾ÍÊÇPython¶ÔÍøÒ³µÄ²Ù×÷¡£
ÕâÆª¼òµ¥ËµÏÂÈçºÎͨ¹ýÍøÖ·ÏÂÔØÍøÒ³£¬Ç°ÌᵱȻÊÇ ......
client:
import socket, sys
if __name__ == '__main__':
#´¦Àí²ÎÊý
argv = sys.argv
if (len(argv)!=3) or (len(argv)==2 and argv[1]=='/?'):
print '>>>Useage:', argv[0], '<address> < ......
ÔÚ½²Êöfilter£¬mapºÍreduce֮ǰ£¬Ê×ÏȽéÉÜÒ»ÏÂÄäÃûº¯Êýlambda¡£
lambdaµÄʹÓ÷½·¨ÈçÏ£ºlambda [arg1[,arg2,arg3,...,argn]] : expression
ÀýÈ磺
>>> add = lambda x,y : x + y
>>> add ......