0

私はここでは完全な初心者であり、どのタイプのコードにもまったく慣れていないため、Python が良い出発点になると思いました。

そのため、複数行にコメントしようとすると、構文エラーが発生します。

コードに追加しました。助けてください。明らかな間違いを許してください。私の行動をお詫び申し上げます。

print ("no comment")
'''
print ("this is a comment")
print ("so is this")
'''    
print (" not a comment")
4

7 に答える 7

0

Comments are not done with ''' or """ that is a way to have a string go across multiple lines how you comment is by doing # for example

#print ("hello world")
#this is a comment
#so is this
#I am a comment
print('I still work')

If you have multiple lines to comment out what you would have to do is use your IDE highlight the text and dependent on your keyboard or computer you press CONTROL+/ or COMMAND+/ I know that works for sublime text 2 but I am not sure about python's default IDLE

Good luck with your future coding !

于 2013-12-15T18:53:05.163 に答える
0

それが何であれ、まず第一に単純なコメントではありませんが、開発者が使用している間

'''text''' or """text"""

また

'''
line 1
line 2
and so on
'''

しかし、ここでは SyntaxError を発生させることは何も悪いことではありません

最初に Python インタープリターのバージョンを確認し、それに応じて実行します

于 2013-10-21T17:35:29.117 に答える
0

私は IndentationError で @iCodez と一緒です。

このページによると: http://docs.python.org/release/2.5.1/ref/indentation.html コードの最初の行はインデントできません。

チェックのために ideone でコードを実行したところ、エラーが発生しました: http://ideone.com/YTuqaG

    print ("no comment")
    '''
    print ("this is a comment")
    print ("so is this")
    '''    
    print (" not a comment")

各行から先頭のスペース/タブを削除してみてください。

于 2013-10-21T17:38:42.047 に答える