PythonÕýÔò±í´ïʽµÄ³£ÓÃÆ¥ÅäÓ÷¨
ÏÂÃæÁгöPythonÕýÔò±í´ïʽµÄ¼¸ÖÖÆ¥ÅäÓ÷¨£º
1.²âÊÔÕýÔò±í´ïʽÊÇ·ñÆ¥Åä×Ö·û´®µÄÈ«²¿»ò²¿·Ö
regex=ur"" #ÕýÔò±í´ïʽ
if re.search(regex, subject):
do_something()
else:
do_anotherthing()
2.²âÊÔÕýÔò±í´ïʽÊÇ·ñÆ¥ÅäÕû¸ö×Ö·û´®
regex=ur"\Z" #ÕýÔò±í´ïʽĩβÒÔ\Z½áÊø
if re.match(regex, subject):
do_something()
else:
do_anotherthing()
3.´´½¨Ò»¸öÆ¥Åä¶ÔÏó£¬È»ºóͨ¹ý¸Ã¶ÔÏó»ñµÃÆ¥Åäϸ½Ú(Create an object with details about how the regex matches (part of) a string)
regex=ur"" #ÕýÔò±í´ïʽ
match = re.search(regex, subject)
if match:
# match start: match.start()
# match end (exclusive): atch.end()
# matched text: match.group()
do_something()
else:
do_anotherthing()
4.»ñÈ¡ÕýÔò±í´ïʽËùÆ¥ÅäµÄ×Ó´®(Get the part of a string matched by the regex)
regex=ur"" #ÕýÔò±í´ïʽ
match = re.search(regex, subject)
if match:
result = match.group()
else:
result = ""
5. »ñÈ¡²¶»ñ×éËùÆ¥ÅäµÄ×Ó´®(Get the part of a string matched by a capturing group)
regex=ur"" #ÕýÔò±í´ïʽ
match = re.search(regex, subject)
if match:
result = match.group(1)
else:
result = ""
6. »ñÈ¡ÓÐÃû×éËùÆ¥ÅäµÄ×Ó´®(Get the part of a string matched by a named group)
regex=ur"" #ÕýÔò±í´ïʽ
match = re.search(regex, subject)
if match:
result = match.group"groupname")
else:
result = ""
7. ½«×Ö·û´®ÖÐËùÓÐÆ¥ÅäµÄ×Ó´®·ÅÈëÊý×éÖÐ(Get an array of all regex matches in a string)
result = re.findall(regex, subject)
8.±éÀúËùÓÐÆ¥ÅäµÄ×Ó´®(Iterate over all matches in a string)
for match in re.finditer(r"<(.*?)\s*.*?/\1
Ïà¹ØÎĵµ£º
python ûÓÐÊý×éµÄÊý¾Ý½á¹¹
#list ÐòÁÐ
sample_list = [1,2,3,'abc']
#dictionary ×Öµä
sample_dic = {"key":value, 2:3}
#tuple Ö»¶ÁµÄÐòÁÐ
sample_tuple = (1,3,"ab")
Ðò±í
Ðò±íÓÉһϵÁÐÖµÓöººÅ·Ö¸ô¶ø³É
Ðò±íÓë×Ö·û´®Ò»ÑùÊDz»¿É±äµÄ£º²»ÔÊÐí¶ÔÐ ......
Ç°¼¸Ìì¿´µ½ÁËÒ»ÐÐÇó1000µÄ½×³ËµÄPython´úÂ룺
print
reduce
(
lambda
x
,
y
:
x
*
y
,
range
(
1
,
1001
))
Ò»ÏÂ×Ó±»python´úÂëµÄ¾«¼ò
Óë½ô´ÕËùÕÛ·þ£¬¹Ê¶Ô´úÂë½øÐÐÁ˼òµ¥µÄ·ÖÎö¡£
reduceÓërange¶¼ÊÇPythonµÄÄÚÖú¯Êý¡£
range£¨1£¬10 ......
pythonµÄeggÎļþÓеãÏñjavaÖеÄjarÎļþ£¬ÊÇÒ»¸ö¹¤³Ì´ò°üÎļþ£¬±ãÓÚ°²×°²¿Ê𣬽ö´ËÒ»µã£¬¸ø¶àÉÙpythoner´øÀ´Á˶àÉÙ¼¤¶¯¡£
ÈçºÎÖÆ×÷eggÎļþÄØ£¿see¹Ù·½Îĵµhttp://peak.telecommunity.com/DevCenter/PythonEggs£¬
µ½http://pypi.python.org/pypi/setuptoolsÏÂÔØsetuptools°ü£¬È»ºó°²×°£º
python setup.py
1.ÖÆ×÷eggÎļþ
......
¼¯ºÏÀàÐͲÙ×÷·û£¨ËùÓеļ¯ºÏÀàÐÍ£©
ÁªºÏ( | )
ÁªºÏ(union)²Ù×÷ºÍ¼¯ºÏµÄOR(ÓֳƿɼæÎöÈ¡(inclusive
disjunction))ÆäʵÊǵȼ۵ģ¬Á½¸ö¼¯
ºÏµÄÁªºÏÊÇÒ»¸öм¯ºÏ£¬¸Ã¼¯ºÏÖеÄÿ¸öÔªËض¼ÖÁÉÙÊÇÆäÖÐÒ»¸ö¼¯ºÏµÄ³ÉÔ±£¬¼´£¬ÊôÓÚÁ½¸ö¼¯ºÏÆä
ÖÐ
Ö®Ò»µÄ³ÉÔ±¡£ÁªºÏ·ûºÅÓÐÒ»¸öµÈ¼ÛµÄ·½·¨£¬union().
Edit By Vheavens
Edit By Vhe ......
1 ÔÚÏëÒª²åÈë¶ÏµãµÄµØ·½²åÈë´úÂë
import pdb
pdb.set_trace()
2È»ºóʹÓÃÖ¸Áî½øÐÐdebug
²é¿´´úÂëÉÏÏÂÎÄ£¬l£¨Ð¡Ð´L£©
¼àÊÓ±äÁ¿ ......