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

PythonÖÐRangeºÍXRangeµÄÇø±ð

PythonÖÐRangeºÍXRangeµÄÇø±ð(Difference between Range and XRange in Python)
×î½ü»úÆ÷³öÁ˵ãÎÊÌ⣬ËùÒÔһֱûÓÐдÐµĶ«Î÷³öÀ´¡£Ö®Ç°ÔÚ¶ÁPythonµÄ´úÂëµÄʱºò£¬·¢¾õºÃ¶àÈËϲ»¶ÓÃXRange£¬¶ø²»ÊÇRange£¬ÎÒÒ²Ö»ÊǼǵÃѧϰµÄʱºò¿ªÊ¼Ñ§µ½µÄÊÇRange£¬ºóÃæÓÖ¿´µ½ÓиöXRange£¬µ±Ê±Ò²Ã»ÓÐÉ£¬ÎªÊ²Ã´PythonÀïÃæÒªÓÐÁ½¸öͬÑùµÄ¹¦ÄܵÄϵͳº¯Êý¡£½ñÌìÔÙÈ¥×Ðϸ²éÁËÏÂÎĵµ£¬Ô­À´ËüÃÇÖ®¼ä»¹ÊÇÓеãÇø±ð£¬ËäÈ»²»ÊǺܴ󣬵«ÖÁÉÙXRangeµÄЧÂÊ»á±ÈRangeµÄ¸ß¡£
ÔÚÎĵµÖÐÊÇÕâÑùдµÄ£ºxrange([start,] stop[, step])This function is very similar to range(), but returns an ``xrange object'' instead of a list. This is an opaque sequence type which yields the same values as the corresponding list, without actually storing them all simultaneously. The advantage of xrange() over range() is minimal (since xrange() still has to create the values when asked for them) except when a very large range is used on a memory-starved machine or when all of the range's elements are never used (such as when the loop is usually terminated with break).Note: xrange() is intended to be simple and fast. Implementations may impose restrictions to achieve this. The C implementation of Python restricts all arguments to native C longs ("short" Python integers), and also requires that the number of elements fit in a native C long.
ÔÚRangeµÄ·½·¨ÖУ¬Ëü»áÉú³ÉÒ»¸ölistµÄ¶ÔÏ󣬵«ÊÇÔÚXRangeÖУ¬ËüÉú³ÉµÄÈ´ÊÇÒ»¸öxrangeµÄ¶ÔÏ󣬵±·µ»ØµÄ¶«Î÷²»ÊǺܴóµÄʱºò£¬»òÕßÔÚÒ»¸öÑ­»·À»ù±¾É϶¼ÊÇ´ÓÍ·²éµ½µ×µÄÇé¿öÏ£¬ÕâÁ½¸ö·½·¨µÄЧÂʲ¶à¡£µ«ÊÇ£¬µ±·µ»ØµÄ¶«Î÷ºÜ´ó£¬»òÕßÑ­»·Öг£³£»á±»Break³öÀ´µÄ»°£¬»¹Êǽ¨ÒéʹÓÃXRange£¬ÕâÑù¼ÈÊ¡¿Õ¼ä£¬ÓÖ»áÌá¸ßЧÂÊ¡£
ÏÂÃæ¾Ù¸öÀý×Ó£º
Èç¹ûʹÓÃrangeº¯Êý£¬Ö´ÐÐÏÂÃæµÄÓï¾ä£¬½«»áµÃµ½ºóÃæµÄ½á¹û£º
>>> a = range(0,100)
>>> print type(a)
>>> print a
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73,


Ïà¹ØÎĵµ£º

PythonʵÏÖ¡°¸÷ÀàÐÍÎļþͳ¼Æ¡±¹¦ÄÜ

²»¶à˵ÁË£¬Ö±½Ó¿´´úÂë°É£¡
import os
path = 'e:/Download/'
kzm = []
kzmTemp = set()
kzmTemp2 = []
dict = {}
for root,dirs,files in os.walk(path):
    for file in files:
        ext = os.path.splitext(file)[1][1:]
      ......

PythonÖ®¸Ð

´ÓÈ¥Ä껹û±ÏÒµ¾Í½Ó´¥Python£¬ÉÏÖÜÓÐЩÎÞÁÄÖØÐÂÔÙ¿´Ò»±é£¬·¢ÏÖÆäȷʵ²»´í¡£Óï·¨¼òµ¥£¬Ò»¸öÏÂÎç»ù±¾Á˽⣬ʹÓÃPydev²å¼þÔÚEclipseÖнøÐпª·¢»ù±¾ÉÏûÓÐÈκÎÕϰ­¡£ÖصãÊÇÆäЧÂʺܸߣ¬²»Ðè±àÒëÖ±½ÓÔËÐС£±È½ÏÊʺϽøÐÐÊý¾ÝµÄÔ¤´¦Àí¡£²»´í£¬ÒÔºóÓлú»áºÃºÃÓÃÓᣠ......

pythonѧϰ£¨1£©£­×Öµä (Dictionary)

   
×ֵ䣨Dictionary£©ÊÇÒ»ÖÖÓ³Éä½á¹¹µÄÊý¾ÝÀàÐÍ£¬ÓÉÎÞÐòµÄ“¼ü£­Öµ¶Ô”×é³É¡£×ÖµäµÄ¼ü±ØÐëÊDz»¿É¸Ä±äµÄÀàÐÍ£¬È磺×Ö·û´®£¬Êý×Ö£¬tuple£»Öµ¿É
ÒÔΪÈκÎpythonÊý¾ÝÀàÐÍ¡£
1¡¢Ð½¨×Öµä
>>> dict1={}     
#½¨Á¢Ò»¸ö¿Õ×Öµä
>>> type(dict1)
<ty ......

Python Áбí(list)²Ù×÷

´´½¨Áбí
sample_list = ['a',1,('a','b')]
Python Áбí²Ù×÷
sample_list = ['a','b',0,1,3]
µÃµ½ÁбíÖеÄijһ¸öÖµ
value_start = sample_list[0]
end_value =
sample_list[-1]
ɾ³ýÁбíµÄµÚÒ»¸öÖµ
del sample_list[0]
ÔÚÁбíÖвåÈëÒ»¸öÖµ
sample_list[0:0] = ['sample value']
µÃµ½ÁбíµÄ³¤¶È
list_length = ......

ÒÔPython Imaging Library ½øÐÐÓ°Ïñ×ÊÁÏ´¦ÀíPIL


1   Ó°ÏñÓëͼÐÎ×ÊÁϵĴ¦Àí
ÌÖÂÛͼÐÎ(Ó°Ïñ) ±¾ÉíµÄ´¦Àí£¬¶øÌÖÂÛµÄÄÚÈݽ«»á¼¯ÖÐÔÚPython Imaging Library (PIL) ÕâÒ»Ì׳Ìʽ¿âÉÏ¡£
PIL ÊÇPython ÏÂ×îÓÐÃûµÄÓ°Ïñ´¦ÀíÌ×¼þ£¬ÓÉÐí¶à²»Í¬µÄÄ£×éËù×é³É£¬²¢ÇÒÌṩÁËÐí¶àµÄ´¦Àí¹¦ÄÜ£¬ÔÊÐíÎÒÃÇÔÚ¼òµ¥µÄPython ³ÌʽÀï½øÐÐÓ°ÏñµÄ´¦Àí¡£ Ê¹ÓÃÏñPIL ÐíÑùµÄ³Ìʽ¿âÌ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ