python ±Ê¼Ç for loop and extend, append
list.append(item)
list.extend(sequence)
http://docs.python.org/tutorial/datastructures.html
http://docs.python.org/library/functions.html Õ⼸Ìì¿´Ò»ÏÂ
python howto
¶÷¡£python documentation ȷʵºÜºÃºÜÇ¿´ó°¡£¡
list.append(x)Add an item to the end of the list; equivalent to a[len(a):] = [x].a[len(a):] ÊÇÒ»¸ölist£¬sliceµÃµ½µÄÒ»¸ölist£¬Ï൱ÓÚ°ÑÕâÒ»¶Î½ØÈ¡³öÀ´µÄlist£¬ÒªÊǵÈÓÚÒ»¸ölist b£¬Ï൱ÓÚÔÚaµÄĩβÌí¼ÓÁËb,µ«ÊÇbÕû¸öÊÇÒ»¸öÔªËØ¡£>>> c.append([1,2,3])>>> c[1, 2, 3, 4, [1, 2, 3]]list.extend(L)Extend the list by appending all the items in the given list; equivalent to a[len(a):] = L.
Ìí¼ÓLÖеÄÔªËØ£¬ÑÓ³¤a
For loop, for(i=0; i<n; i++) in python is for i in range(0, n)
¶ÔÓÚ²½³¤Îª2£¬Ôò for i in range(0, n, 2): range º¯Êý¿ÉÒԸı䲽³¤£¡ ²»Óà i += 2£¬ Markһϡ£
for i in range(0,10,2):
print i
0
2
4
6
8
±ÈÈçÑ°ÕÒËØÊýµÄ³ÌÐò¡£ÄÇô£¬Ñ°ÕÒÊDz»ÊDZ»Õû³ýµÄʱºò£¬³ýÁË2 Ö®Í⣬¿ÉÒÔ´Ó3¿ªÊ¼£¬²½³¤Îª2µÄÈ¥ËÑË÷¡£Ö±µ½[sqrt(prime_n)](¾ÍÊÇint(sqrt(prime_n))£¬ ¸ß˹º¯Êý)Ϊֹ¡£
Ïà¹ØÎĵµ£º
1£® Ê×ÏȾÍÊÇÔÚ±àÒëÆ÷ÖаÑpython°²×°Ä¿Â¼include/Óëlibs/¼ÓÈ룬¶ÔÓÚÕâµãÎÒÔÚvc6ÖпÉÒÔ£¬µ«ÊÇÔÚdev c++Öм´Ê¹¼ÓÈëÁ˱àÒëÒ²»á³ö´í£¬ËµÕÒ²»µ½pythonÍ·Îļþ£¬Õâµã±È½ÏÓôÃÆ£¬²»¹ý¿¼Âǵ½Ò»°ãwindows±à³Ì¶¼ÓõÄÊÇvc£¬ËùÒÔ²¢Ã»ÓÐʲôӰÏì°É£¡£¡£¡
È»ºóÓÃ#include <Python.h>¾Í¿ÉÒÔ°ÑpythonµÄÖ÷Í·Îļþ°üº¬½øÀ´ÁË¡£
µ«Ê ......
import urllib
from HTMLParser import HTMLParser
class TitleParser(HTMLParser):
def __init__(self):
self.title = ''
self.divcontent = ''
self.readingtitle = 0
self.readingdiv = 0
HTMLParser.__init__(self)
def handle_starttag(self, tag, attrs):
......
1£¬ÏÂÔØorg.python.pydev.feature-1.5.0.1251989166.zip http://sourceforge.net/projects/pydev/files/
2£¬°²×°²å¼þµ½eclipse
3£¬ÖØÆôeclipse
×¢Ò⣺ʹÓÃ1.5.6°æ±¾pydev²å¼þ£¬´´½¨python¹¤³Ì»á±¨´í£¬Ê¹ÓÃ1.5.0°æ±¾ÎÞ´ËÎÊÌâ¡£ ......
1£¬±àдServer.py
import socket
s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
s.bind(('localhost',8081))
while True:
data,addr=s.recvfrom(1024)
print 'receive:',data,'from',addr
2£¬±àдClient.py
import socket
s=socket.socket(socket.AF_INET,socket.SOC ......
¶ÓÁУº
Óë¶ÑÕ»ÀàËÆ£¬Í¨¹ýpythonµÄÁбíÀàÐÍÀ´ÊµÏÖ£¬²Î¿¼ help(list)
shoplist=['apple','mango','carrot','banana']
print 'I have',len(shoplist),'items to purchase'
print 'these items are:'
for item in shoplist:
print item,
shoplist.append('rice')
print 'my shopping list is now', shoplist
shoplist. ......