Python,包含整个cod的注释

2024-09-26 17:45:38 发布

您现在位置:Python中文网/ 问答频道 /正文

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

"""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

Tags: and代码instringifcountprintsone
1条回答
网友
1楼 · 发布于 2024-09-26 17:45:38

不能:Python注释是单行的。和docstrings不是注释。但是,在开发过程中,如果您需要“关闭”一个代码块,您可以将它放入if False:块中。在

例如:

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

相关问题 更多 >

    热门问题