开发者

reason for using three open-close quotes when using re.verbose in python

I'm jus开发者_运维技巧t curious as to why most examples I've seen that make use of re.verbose when using regular expressions, use '''?

An example I found is shown below

address = re.compile(
    '''              #THIS
    [\w\d.+-]+       # username
    @
    ([\w\d.]+\.)+    # domain name prefix
    (com|org|edu)    # we should support more top-level domains
    ''',             #AND  THIS  
    re.UNICODE | re.VERBOSE)


Using ''' allows the string to span multiple lines, so they can break down each part of the re instead of having one long line.

It is done for code readability, not functionality.

See the Python Tutorial strings section for more information about strings that span multiple lines.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜