Python,包含整个代码的注释

Python, comment that wraps entire code

试图用注释包装整个代码,我该怎么做?我试过,但没有成功,作为一个问题,这是可能的吗?我想我会把评论放在其他评论之上,但我确定有一种方法,我会包装这段代码,因为我想把它和其他项目放在同一个文件中,但我不想激活所有的代码。以下是我要作为注释包装的代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""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


不能:python注释是单行的。文档字符串不是注释。但是,在开发过程中,如果您需要"关闭"一个代码块,您可以将它放入一个if False:块。

如:

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