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))£¬ ¸ß˹º¯Êý)Ϊֹ¡£
Ïà¹ØÎĵµ£º
ǰÁ½ÌìÀí½âÁËunicode¡¢utf-8¡¢gb2312ÕâЩ±àÂëÖ®¼äµÄ¹ØÏµÒԺ󣬽ñÌìÖÕÓÚŪÃ÷°×ÁËÔÚpythonÀïÃæµÄ±àÂëÎÊÌâ¡£ÎÒÃÇÔÚдpython½Å±¾Ê±Èç¹ûÓÐÖÐÎĵÄ×Ö·û´®£¬ÔÚÔËÐеÄʱºòÓпÉÄܻᱨ´íÒ²ÓпÉÄÜ»á³öÏÖÂÒÂë¡£Ò»°ã¼ÓÉÏ# -*- coding:utf-8 -*-¾Í²»»á±¨´íÁË£¬µ«ÊÇ»¹¿ÉÄÜÓÐÂÒÂëÎÊÌ⣬¶øÇÒͬÑùµÄ´úÂëÔÚ²»Í¬µÄ±à¼Æ÷ÖеóöµÄ½á¹û ......
Íò¶ñµÄ±àÂë
С²Ë¶ÔÓÚÀÏʦÉÏÒ»½Ú½²µÄ²»ÊǺÜÃ÷°×£¬ÒòΪûÓÐÒ»±¾ÊéÊǽ«ÎļþÓëwebÒ»Æð½²Êڵģ¬Ëû¾ö¶¨×Ô¼ºÌ½¾¿Ò»ÏÂËüÃÇÖ®¼äµÄ²»Í¬£º
Ê×ÏÈ£¬Ð¡²ËÔÚCÅ̽¨ÁËÒ»¸öÎı¾Îĵµ file.txt,ÊäÈëËĸö×Ö£ºÎÒÊÇС²Ë¡£
È»ºó£¬Ð¡²ËÔÚshellÖÐÁ·Ï°ÆðÀ´£º
>>> file=open("c:\\file.txt","r")
>>> data=file.read()
>> ......
#from pp3e Chapter 9.3
#############################################################################
# popup three new window, with style
# destroy() kills one window, quit() kills all windows and app; top-level
# windows have title, icon, iconify/deiconify and protocol for wm events;
# there ......
ÕÛÌÚ¼ÆËã»ú£¬±»¼ÆËã»úÕÛÌÚ£¬Ç°Ç°ºóºóÒ²ÓÐÊ®¼¸Äê¡£
×î¿É±¯µÄÊǾÓȻһÎÞËù³É£¬ËäÈ»½ö½ö³öÓÚÐËȤ£¬²¢ÎÞ¹¤×÷֮ѹÁ¦£¬µ«ÊÇÕâÖÖ´ìÕÛ¸ÐȷʵÊÇʵ´òʵµÄ¡£
ÒѾ¼Ç²»ÆðÊÇÄÄÒ»ÌìÁË£¬ºÃÏñͻȻ¾ÍÖªµÀÁËpythonµÄ´æÔÚ£¬´Ó×î³õµÄ²»¾Ò⣬µ½Ô½À´Ô½Ï²°®£¬ÎÒÒ»²½²½µÄÏòpython¿¿½ü¡£
ÎÒϲ»¶Python£¬ÕâÊÇÒ»¸öÊÂʵ£¬ÎÒ׫´ ......