PythonÈëÃŵÄ36¸öÀý×Ó Ö® 24
# 027
toolName = 'Google'
if toolName.startswith('Go'):
print 'The tool\'s name starts with \"Go\".'
if 'oo' in toolName:
print 'The tool\'s name contains the stirng "oo".'
print toolName.find('gl') # ·µ»ØÊ״γöÏÖ“gl”×Ö·û´®µÄË÷Òý
if toolName.find('Baidu'):
print 'Can\'t find "Baidu" in tool\'s name.'
aList = ['a','b','c']
print '...'.join(aList)
output£º
The tool's name starts with "Go".
The tool's name contains the stirng "oo".
3
Can't find "Baidu" in tool's name.
a...b...c
Ïà¹ØÎĵµ£º
1. Basic
²Î¿¼¡¶PythonÕýÔò±í´ïʽ²Ù×÷Ö¸ÄÏ¡·
Ä£¿ére£¬perl·ç¸ñµÄÕýÔò±í´ïʽ
regex²¢²»Äܽâ¾öËùÓеÄÎÊÌ⣬ÓÐʱºò»¹ÊÇÐèÒª´úÂë
regex»ùÓÚÈ·¶¨ÐԺͷÇÈ·¶¨ÐÔÓÐÏÞ×Ô¶¯»ú
2. ×Ö·ûÆ¥Åä(ÑÐò½¥½ø)
Ôª×Ö·û
. ^ $ * + ? { [ ] \ | ( )
1) "[" ºÍ "]"³£ÓÃÀ´Ö¸¶¨Ò»¸ö×Ö·ûÀà±ð£¬Ëùν×Ö·ûÀà±ð¾ÍÊÇÄãÏëÆ¥ÅäµÄÒ»¸ö×Ö·û¼¯¡£Èç[ ......
¡¡¡¡StringIOµÄÐÐΪÓëfile¶ÔÏó·Ç³£Ïñ£¬µ«Ëü²»ÊÇ´ÅÅÌÉÏÎļþ£¬¶øÊÇÒ»¸öÄÚ´æÀïµÄ¡°Îļþ¡±£¬ÎÒÃÇ¿ÉÒÔ½«²Ù×÷´ÅÅÌÎļþÄÇÑùÀ´²Ù×÷StringIO¡£Ò»¸ö¼òµ¥µÄÀý×Ó£¬ÈÃÄã¶ÔStringIOÓÐÒ»¸ö¸ÐÐÔµÄÈÏʶ£º 1 #coding=gbk 2 3 import StringIO, cStringIO, sys 4 5 s ......
# 004
# ÀûÓÃÈýÒýºÅ(''' or """)¿ÉÒÔָʾ¶àÐÐ×Ö·û´®
print '''line1
line2
line3'''
# ÁíÍ⣬Ä㻹¿ÉÒÔÔÚÈýÒýºÅÖÐÈÎÒâʹÓõ¥ÒýºÅºÍË«ÒýºÅ
print ''' "What's up? ," he replied.'''
# ·ñÔò£¬ÄãºÃʹÓÃתÒå·ûÀ´ÊµÏÖͬÑùµÄЧ¹û
# »¹ÊÇʹÓÃÈýÒýºÅºÃ£¬²»È»¾ÍÆÆ»µÁËÊÓ¾õÃÀÁË
print ' \"Wha ......
¡¡¡¡ÓÐʱºò£¬Òª°ÑÄÚ´æÖеÄÒ»¸ö¶ÔÏó³Ö¾Ã»¯±£´æµ½´ÅÅÌÉÏ£¬»òÕßÐòÁл¯³É¶þ½øÖÆÁ÷ͨ¹ýÍøÂç·¢Ë͵½Ô¶³ÌÖ÷»úÉÏ¡£PythonÖÐÓкܶàÄ£¿éÌṩÁËÐòÁл¯Óë·´ÐòÁл¯µÄ¹¦ÄÜ£¬È磺marshal, pickle, cPickleµÈµÈ¡£½ñÌì¾Í½²½²marshalÄ£¿é¡£
¡¡¡¡×¢Ò⣺
marshal²¢²»ÊÇÒ»¸öͨÓõÄÄ£¿é£¬ÔÚijЩʱºòËüÊÇÒ»¸ö²»±»ÍƼöʹÓõÄÄ£¿é£¬ÒòΪʹÓÃmarshalÐ ......
Ô´´úÂëÏÂÔØ£ºÏÂÔصØÖ·ÔÚÕâÀï
# 022
listNum1 = [1, 3]
listNum2 = [2, 4]
listStr1 = ['a', 'c']
listStr2 = ['b', 'd']
# ÁбíµÄºÏ²¢
list1 = listNum1 + listStr1
for ele in list1:
print ele
print '\n'
# ÅжÏÁбíÖÐÊÇ·ñ°üº¬Ä³ÔªËØ
print 'b' in list1
print 1 in list1
# ɾ³ýij¸öÔªËØ
for ele in ......