Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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 ÖеÄ×Ö·û±àÂë

1¡¢strÀàÐÍ¿ÉÒÔÀí½âΪһ¸ö¶þ½øÖÆblock£¬»òmultibyte
2¡¢multibyte_str.decode("<multibyte_encode_method>")  -> unicode
3¡¢unicode_str.encode("<multibyte_encode_method>")  -> multibyte_str(binary block)
4¡¢unicode_str µÄ²Ù×÷²ÎÊýҲӦΪunicode£¬È磺unicode_str.find("Ñù±¾".deco ......

ÈçºÎÔËÐÐPython½Å±¾

¼ÙÉèÄãÄãµÄ²Ù×÷ϵͳÊÇWinXP£º

¿ªÊ¼²Ëµ¥-> ÔËÐÐ-> cmd

È»ºó¾Í¿ÉÒÔÇÃÃüÁîÁË¡£

Èç¹ûÄãÓÃIDLE£¬¿ÉÒÔÓÃIDLE´ò¿ªÕâ¸ö.pyÎļþ£¬È»ºóÔڲ˵¥ "Run "ÏÂÓÐÒ»Ïî "Run   Module "£¬µã»÷¼´¿É¡£ ......

Python TKinter Gui: Toplevel window

#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¶ÁдÎļþ


1.open
ʹÓÃopen´ò¿ªÎļþºóÒ»¶¨Òª¼ÇµÃµ÷ÓÃÎļþ¶ÔÏóµÄclose()·½·¨¡£±ÈÈç¿ÉÒÔÓÃtry/finallyÓï¾äÀ´È·±£×îºóÄܹرÕÎļþ¡£
file_object = open('thefile.txt')
try:
     all_the_text = file_object.read( )
finally:
     file_object.close( )
×¢£º²»Ä ......

»°ËµPython£¨ËÄ£©»¶Ó­Ð¡Âéȸ

С°×ÊǸö΢ÈíÃÔ£¬ËûµÄżÏñÊDZȶû´óÊ壬ԭÒòµ±È»ÊǵØÇòÈ˶¼ÖªµÀÀ²¡£´ó¶þµÄʱºò£¬ËûµÄ“ê¡Ñ§¼Æ»®”ÔøÒ»¶ÈµÃ³Ñ£¬Ô­ÒòÊÇËû¹Ò¿ÆÌ«¶à¡£µ±È»£¬´óÈýÐÂѧÆÚ¿ªÊ¼µÄʱºò£¬Ãæ¶Ô¹«ÖÚÖÊÒÉ£¬Ð¡°×Õ¾ÔÚÒÎ×ÓÉÏ£¬Ïñ¼«ÁË¡¶´óÄÚÃÜ̽ÁãÁã·¢¡·ÀïµÄÎ÷ÃÅ´µÑ©£º“ÊÀ½çÊ׸»±È²»Ò»¶¨Óжà³öÉ«£¬ÕâÖ»²»¹ýÊÇÄãÃÇÕâЩÐǶ·ÊÐÃñÒ»ÏáÇéÔ¸µÄÏë·¨° ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ