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

Python ×Ö·û´®·½·¨Ïê½â


ÀàÐÍ
·½·¨
×¢½â
Ìî³ä
center(width[, fillchar]) ,
ljust(width[, fillchar]),
rjust(width[, fillchar]),
zfill(width),
expandtabs([tabsize])
l        
fillchar ²ÎÊýÖ¸¶¨ÁËÓÃÒÔÌî³äµÄ×Ö·û£¬Ä¬ÈÏΪ¿Õ¸ñ
l        
¹ËÃû˼Ò壬zfill()¼´ÊÇÒÔ×Ö·û0½øÐÐÌî³ä£¬ÔÚÊä³öÊýֵʱ±È½Ï³£ÓÃ
l        
expandtabs()µÄtabsize ²ÎÊýĬÈÏΪ8¡£ËüµÄ¹¦ÄÜÊÇ°Ñ×Ö·û´®ÖеÄÖƱí·û£¨tab£©×ª»»ÎªÊʵ±ÊýÁ¿µÄ¿Õ¸ñ¡£
ɾ¼õ
strip([chars]),
lstrip([chars]),
rstrip([chars])
*strip()º¯Êý×åÓÃÒÔÈ¥³ý×Ö·û´®Á½¶ËµÄ¿Õ°×·û£¬¿Õ°×·ûÓÉstring.whitespace³£Á¿¶¨Òå¡£
±äÐÎ
lower(),
upper(),
capitalize(),
swapcase(),
title()
title()º¯ÊýÊDZȽÏÌرðµÄ£¬ËüµÄ¹¦ÄÜÊǽ«Ã¿Ò»¸öµ¥´ÊµÄÊ××Öĸ´óд£¬²¢½«µ¥´ÊÖеķÇÊ××Öĸת»»ÎªÐ¡Ð´£¨Ó¢ÎÄÎÄÕµıêÌâͨ³£ÊÇÕâÖÖ¸ñʽ£©¡£
>>> 'hello wORld!'.title()
'Hello World!'
ÒòΪtitle() º¯Êý²¢²»È¥³ý×Ö·û´®Á½¶ËµÄ¿Õ°×·ûÒ²²»»á°ÑÁ¬ÐøµÄ¿Õ°×·ûÌ滻Ϊһ¸ö¿Õ¸ñ£¬ËùÒÔ½¨ÒéʹÓÃstring Ä£¿éÖеÄcapwords(s)º¯Êý£¬ËüÄܹ»È¥³ýÁ½¶ËµÄ¿Õ°×·û£¬ÔÙ½«Á¬ÐøµÄ¿Õ°×·ûÓÃÒ»¸ö¿Õ¸ñ´úÌæ¡£
>>> ' hello   world!'.title()
' Hello   World!'
>>> string.capwords(' hello   world!')
'Hello World!'
 
·ÖÇÐ
partition(sep),
rpartition(sep),
splitlines([keepends]),
split([sep [,maxsplit]]),
rsplit([sep[,maxsplit]])
l        
*partition()
º¯Êý×åÊÇ2.5°æ±¾ÐÂÔöµÄ·½·¨¡£Ëü½ÓÊÜÒ»¸ö×Ö·û´®²ÎÊý£¬²¢·µ»ØÒ»¸ö3¸öÔªËØµÄ tuple ¶ÔÏó¡£Èç¹ûsepû³öÏÖÔÚĸ´®ÖУ¬·µ»ØÖµÊÇ (sep,
‘’, ‘’)£»·ñÔò£¬·µ»ØÖµµÄµÚÒ»¸öÔªËØÊÇ sep ×ó¶ËµÄ²¿·Ö£¬µÚ¶þ¸öÔªËØÊÇ sep ×ÔÉí£¬µÚÈý¸öÔªËØÊÇ sep ÓҶ˵IJ¿·Ö¡£
l        
²ÎÊý maxsplit ÊÇ·ÖÇеĴÎÊý£¬¼´×î´óµÄ·ÖÇдÎÊý£¬ËùÒÔ·µ»ØÖµ×î¶àÓÐ maxsplit+1 ¸öÔªËØ¡£
l        
s.split() ºÍ s.split(‘ ‘)µÄ·µ»ØÖµ²»¾¡Ïàͬ
>>> ' hello   world!'.split()
['hello', 'world!']
>&


Ïà¹ØÎĵµ£º

pythonÖг£ÓÃÈÕÆÚ²Ù×÷×ܽá

http://hbszyandong.javaeye.com/blog/377199
# -*- coding: utf-
8
 -*-  
from datetime import
 datetime  
from datetime import
 date  
from time import
 strftime  
from time imp ......

Python×Ö·û´®µÄencodeÓëdecode

 
Ê×ÏÈÒª¸ãÇå³þ£¬×Ö·û´®ÔÚPythonÄÚ²¿µÄ±íʾÊÇunicode±àÂ룬Òò´Ë£¬ÔÚ×ö±àÂëת»»Ê±£¬Í¨³£ÐèÒªÒÔunicode×÷ΪÖмä±àÂ룬¼´ÏȽ«ÆäËû±àÂëµÄ×Ö·û´®½âÂ루decode£©³Éunicode£¬ÔÙ´Óunicode±àÂ루encode£©³ÉÁíÒ»ÖÖ±àÂë¡£
decodeµÄ×÷ÓÃÊǽ«ÆäËû±àÂëµÄ×Ö·û´®×ª»»³Éunicode±àÂ룬Èçstr1.decode('gb2312')£¬±íʾ½«gb2312±àÂëµÄ×Ö· ......

python ÖÐÎÄÂÒÂë ÎÊÌâÉîÈë·ÖÎö

 
ת×Ô:http://hi.baidu.com/%C1%EE%BA%FC%CF%F3/blog/item/efb76fb7f0411dc437d3ca20.html
 
ÔÚ±¾ÎÄÖУ¬ÒÔ'¹þ'À´½âÊÍ×÷ʾÀý½âÊÍËùÓеÄÎÊÌ⣬“¹þ”µÄ¸÷ÖÖ±àÂëÈçÏ£º
  1. UNICODE (UTF8-16)£¬C854£»
  2£® UTF-8£¬E59388£»
  3£® GBK£¬B9FE¡£
Ò»¡¢pythonÖÐ ......

pythonÖÐÎÄĿ¼

 ÈçÓÐһ·¾¶"e:/software/²âÊÔ.txt" 
ÐèҪͨ¹ýpyhon¶Á/д "²âÊÔ.txt"Îļþ£¬¿ÉÒÔ²ÉÓÃÏÂÃæµÄ·½·¨£º 
ipath = "e:/software/²âÊÔ.txt" 
uipath = unicode(ipath , "utf8") 
È»ºóÓÃ"uipath"¾­¹ý±àÂëºóµÄ·¾¶È¥open()¼´¿É¡£ 
ÏÂÃæÊÇÎÒÔÚÏîÄ¿ÖÐÓÃpython¶ÁдexcelµÄÒ»µãÌå»á(½â¾öÁ˶ÁÖÐÎÄÎļþà ......

Python×Ö·û¼¯±àÂëºÍÎļþ¶Áд

 ÕâƪÎÄÕ½²µÃ±È½ÏÇå³þpythonµÄ×Ö·û´®±àÂëÎÊÌâ
Ô­Îijö´¦:http://hi.baidu.com/yobin/blog/item/894158b575090dcb37d3ca07.html
------------------------------------------------------------------
×Ö·û´®±àÂë
pythonÖÐĬÈϱàÂëÊÇASCII£¬¿ÉÒÔͨ¹ýÒÔÏ·½Ê½ÉèÖúͻñÈ¡£º
import sys
print sys.getdefa ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ