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

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))£¬ ¸ß˹º¯Êý)Ϊֹ¡£


Ïà¹ØÎĵµ£º

Python Ï̳߳صÄʵÏÖ

import urllib2
import time
import socket
from datetime import datetime
from thread_pool import *

def main():
url_list = {"sina":"http://www.sina.com.cn",
"sohu":"http://www.sohu.com",
"yahoo":"http://www.yahoo.com",
"xiaonei":"http://www.x ......

PythonÖÐreactor,factory,protocolµÄѧϰ±Ê¼Ç


PythonÖÐreactor,factory,protocolµÄѧϰ±Ê¼Ç
 
 
×îΪ¼òµ¥µÄÇé¿öÏ£¬³ýÁËÁ˽âÇåreactorµÄ¼òµ¥Ê¹Óã¬Ä㻹ҪÁ˽âProtocolºÍFactory¡£ËüÃÇ×îÖÕ¶¼»áÓÉreactorµÄÕìÌý½¨Á¢ºÍrunÀ´Í³Ò»µ÷¶ÈÆðÀ´¡£    
   
     ½¨Á¢·þÎñÆ÷µÄµÚÒ»¸öÒª½â¾öµÄÎÊÌâ¾ÍÊÇ·þÎñÓëÍâ½çµÄ½»Á÷Э ......

python challenge

from: http://www.cnblogs.com/jimnox/archive/2009/12/08/tips-to-python-challenge.html
Python ChallengeÊÇÒ»¸öÍøÒ³´³¹ØÓÎÏ·£¬Í¨¹ýһЩÌáʾÕÒ³öÏÂÒ»¹ØµÄÍøÒ³µØÖ·¡£ÓëÖÚ²»Í¬µÄÊÇ£¬ËüÊÇרÃÅΪ³ÌÐòÔ±Éè¼ÆµÄ£¬ÒòΪ´ó¶àÊý¹Ø¿¨¶¼Òª±à³ÌÀ´ËãŶ£¡£¡
È¥ÄêºÍͬѧһÆðÍæµÄ£¬Ëû×öÁË´ó°ë£¬ÎÒ×öÁËС°ë£¬×÷±×ÁËһЩ£¬33¹ØÈ«Í¨£¬½ ......

ʹÓÃpython»ñÈ¡htmlÒ³ÃæµÄÄÚÈÝ

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): ......

»ù±¾Êý¾Ý½á¹¹µÄpythonʵÏÖ ¶ÓÁÐ

¶ÓÁУº
Óë¶ÑÕ»ÀàËÆ£¬Í¨¹ý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. ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ