python怎么添加多行注释_有没有办法在Python中创建多行注释?
从公认的答案来看。。。You can use triple-quoted strings. When they're not a docstring (first thing in a class/function/module), they are ignored.这根本不是真的。与注释不同,三引号字符串仍然被解析,并且必须在语法上有效,而不管它们在源代码中出现在哪里。如果你试图运行此代码。。。
从公认的答案来看。。。You can use triple-quoted strings. When they're not a docstring (first thing in a class/function/module), they are ignored.
这根本不是真的。与注释不同,三引号字符串仍然被解析,并且必须在语法上有效,而不管它们在源代码中出现在哪里。
如果你试图运行此代码。。。def parse_token(token):
"""
This function parses a token.
TODO: write a decent docstring :-)
"""
if token == '\\and':
do_something()
elif token == '\\or':
do_something_else()
elif token == '\\xor':
'''
Note that we still need to provide support for the deprecated
token \xor. Hopefully we can drop support in libfoo 2.0.
'''
do_a_different_thing()
else:
raise ValueError
你要么。。。ValueError: invalid \x escape
…在Python2.x或。。。SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 79-80: truncated \xXX escape
…在Python 3.x上
做被解析器忽略的多行注释的唯一方法是。。。elif token == '\\xor':
# Note that we still need to provide support for the deprecated
# token \xor. Hopefully we can drop support in libfoo 2.0.
do_a_different_thing()
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
所有评论(0)