PythonÈëÃŵÄ36¸öÀý×Ó Ö® 23
Ô´´úÂëÏÂÔØ£ºÏÂÔصØÖ·ÔÚÕâÀï
# 026
aList = ['1','2','3','4']
aListCopy = aList # Æäʵ£¬ÕâÀï½ö½ö¸´ÖÆÁËÒ»¸öÒýÓÃ
del aList[0]
print aList
print aListCopy # Á½¸öÒýÓÃÖ¸ÏòÁËÁËͬһ¸ö¶ÔÏó£¬ËùÒÔ´òÓ¡½á¹ûÒ»Ñù
aListCopy = aList[:] # ÕâÊǸ´ÖÆÕû¸ö¶ÔÏóµÄÓÐЧ·½·¨
del aList[0]
print aList
print aListCopy
output£º
['2', '3', '4']
['2', '3', '4']
['3', '4']
['2', '3', '4']
Ïà¹ØÎĵµ£º
1. Basic
²Î¿¼¡¶PythonÕýÔò±í´ïʽ²Ù×÷Ö¸ÄÏ¡·
Ä£¿ére£¬perl·ç¸ñµÄÕýÔò±í´ïʽ
regex²¢²»Äܽâ¾öËùÓеÄÎÊÌ⣬ÓÐʱºò»¹ÊÇÐèÒª´úÂë
regex»ùÓÚÈ·¶¨ÐԺͷÇÈ·¶¨ÐÔÓÐÏÞ×Ô¶¯»ú
2. ×Ö·ûÆ¥Åä(ÑÐò½¥½ø)
Ôª×Ö·û
. ^ $ * + ? { [ ] \ | ( )
1) "[" ºÍ "]"³£ÓÃÀ´Ö¸¶¨Ò»¸ö×Ö·ûÀà±ð£¬Ëùν×Ö·ûÀà±ð¾ÍÊÇÄãÏëÆ¥ÅäµÄÒ»¸ö×Ö·û¼¯¡£Èç[ ......
¶þÔªÔËËã·û¼°Æä¶ÔÓ¦µÄÌØÊâ·½·¨
¶þÔªÔËËã·û
ÌØÊâ·½·¨
+
__add__,__radd__
-
__sub__,__rsub__
*
__mul__,__rmul__
/
__div__,__rdiv__,__truediv__,__rtruediv__
//
__floordiv__,__rfloordiv__
%
__mod__,__rmod__
**
__pow__,__rpow__
<<
__lshift__,__rlshift__
>>
_ ......
¡¡¡¡StringIOµÄÐÐΪÓëfile¶ÔÏó·Ç³£Ïñ£¬µ«Ëü²»ÊÇ´ÅÅÌÉÏÎļþ£¬¶øÊÇÒ»¸öÄÚ´æÀïµÄ¡°Îļþ¡±£¬ÎÒÃÇ¿ÉÒÔ½«²Ù×÷´ÅÅÌÎļþÄÇÑùÀ´²Ù×÷StringIO¡£Ò»¸ö¼òµ¥µÄÀý×Ó£¬ÈÃÄã¶ÔStringIOÓÐÒ»¸ö¸ÐÐÔµÄÈÏʶ£º 1 #coding=gbk 2 3 import StringIO, cStringIO, sys 4 5 s ......
Ê×ÏÈÒª¸ãÇå³þ£¬×Ö·û´®ÔÚPythonÄÚ²¿µÄ±íʾÊÇunicode±àÂ룬Òò´Ë£¬ÔÚ×ö±àÂëת»»Ê±£¬Í¨³£ÐèÒªÒÔunicode×÷ΪÖмä±àÂ룬¼´ÏȽ«ÆäËû±àÂëµÄ×Ö·û´®½âÂ루decode£©³Éunicode£¬ÔÙ´Óunicode±àÂ루encode£©³ÉÁíÒ»ÖÖ±àÂë¡£
decodeµÄ×÷ÓÃÊǽ«ÆäËû±àÂëµÄ×Ö·û´®×ª»»³Éunicode±àÂ룬Èçstr1.decode('gb2312')£¬±íʾ½«gb2312±àÂëµÄ×Ö·û´®×ª»»³ ......
¡¡¡¡ÓÐʱºò£¬Òª°ÑÄÚ´æÖеÄÒ»¸ö¶ÔÏó³Ö¾Ã»¯±£´æµ½´ÅÅÌÉÏ£¬»òÕßÐòÁл¯³É¶þ½øÖÆÁ÷ͨ¹ýÍøÂç·¢Ë͵½Ô¶³ÌÖ÷»úÉÏ¡£PythonÖÐÓкܶàÄ£¿éÌṩÁËÐòÁл¯Óë·´ÐòÁл¯µÄ¹¦ÄÜ£¬È磺marshal, pickle, cPickleµÈµÈ¡£½ñÌì¾Í½²½²marshalÄ£¿é¡£
¡¡¡¡×¢Ò⣺
marshal²¢²»ÊÇÒ»¸öͨÓõÄÄ£¿é£¬ÔÚijЩʱºòËüÊÇÒ»¸ö²»±»ÍƼöʹÓõÄÄ£¿é£¬ÒòΪʹÓÃmarshalÐ ......