Python,包含整个代码的注释

时间:2015-08-24 15:58:15

标签: python comments

一直在尝试将整个代码包装在评论中,我该怎么做?我试过#,""",没有成功,作为一个问题,这甚至可能吗?我想我在其他评论之上堆叠评论,但我确定有一种方法,我包装这个代码,因为我想将它与同一文件中的其他项目一起保存在一个文件中,但我不想激活所有代码。这里是我想要包装的代码作为评论:

"""Artithmetic expressions"""

addition = 1 + 1;
subtraction = 2-1;
miltiplication = 2*2;
division = 5/3; """5/3 = 1"""

"""Variables and Assignment"""

a, b = addition, subtraction; """a = addition, b = subtraction"""

""" prints 2 1"""
print a, b 

"""Strings, indexing strings"""

string1 = "hello world hell"

string2 = string1[2] 
"""prints 1"""
print string2 

"""string extraction"""

string3 = string1[0:5]
""" hello """
print string3 

"""Finding"""

stringfind1 = string1.find("hell", 4)
""" prints 12 """
print stringfind1 






"""Python 2"""
"""If statement"""
if (3 < 10):
print "true"

else:
print "false"


""" Logical Operators"""

if (3 and 4 < 10): 
print "true"
"""may use or"""


"""Loops, ex prints 10 iterations"""
count = 0
while (count < 10):
print 'The count is: ', count
count = count + 1

print "Good bye!"

"""converting between numbers and strings: str(one) converts int to     string"""
"""use 'ord' for string --> int, lastly chr = """
one = 1
convert = str(one) 
if convert == 1:
print "true"

else:
print "false"

'''returns one character string from number input'''
var1 = chr(65)
print var1


"""splitting strings: () prints all words in a string"""
""" ' ', 1   prints all except the last word?"""
string10 = "fucking hell i hate your life"
var2 = string10.split()

print var2
print string10.split(' ', 1)


"""Looping through strings with 'for' loop, ex prints all chars in 'string10' in new lines"""

for fuckoff in string10:
print 'Current letter :', fuckoff

1 个答案:

答案 0 :(得分:1)

你不能:Python评论是单行的。 docstrings不是评论。但是,在开发期间,如果您需要关闭&#34;一段代码,您可以将其放入if False:块。

例如:

if False:
    addition = 1 + 1;
    subtraction = 2-1;
    miltiplication = 2*2;
    division = 5/3;