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 deprecatedtoken \xor. Hopefully we can drop support in libfoo 2.0.'''do_a_different_thing()
else:raise ValueError
你会得到…
ValueError: invalid \x escape
…在Python 2. 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()
"""print("What's your name? ")myName = input()print("It's nice to meet you " + myName)print("Number of characters is ")print(len(myName))age = input("What's your age? ")print("You will be " + str(int(age)+1) + " next year.")
"""a = input()print(a)print(a*5)
def foo():"This is a doc string."# A single line comment"""Thisis a multilinecomment/String""""""print "This is a sample foo function"print "This function has no arguments""""return True
hello = "Hello!" # This is an inline commentprint(hello)
你好!
请注意,字符串文字中的哈希字符只是一个哈希字符。
dial = "Dial #100 to make an emergency call."print(dial)
拨打#100拨打紧急电话。
哈希字符也可用于单行或多行注释。
hello = "Hello"world = "World"# First print hello# And print worldprint(hello)print(world)
你好
世界
用三重双引号将文本括起来以支持docstring。
def say_hello(name):"""This is docstring comment andit's support multi line.:param name it's your name:type name str"""return "Hello " + name + '!'
print(say_hello("John"))
你好,约翰!
用三重单引号封闭文本以进行块注释。
'''I don't care the parameters anddocstrings here.'''