Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'syntax': 0.04; 'assignment': 0.07; 'correct.': 0.07; 'string': 0.09; 'comment,': 0.09; 'literal': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'sake': 0.09; 'strings.': 0.09; 'subject:Why': 0.09; 'python': 0.11; "'''": 0.16; 'bhatt': 0.16; 'finney': 0.16; 'interpreter,': 0.16; 'literal,': 0.16; 'literal.': 0.16; 'literals.': 0.16; 'patience': 0.16; 'quoted': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:comment': 0.16; 'subject:quoted': 0.16; 'subject:simple': 0.16; 'subject:triple': 0.16; 'substituted': 0.16; 'followed': 0.16; 'file,': 0.19; 'rules': 0.22; 'header :User-Agent:1': 0.23; 'error': 0.23; 'sort': 0.25; 'source': 0.25; 'header:X-Complaints-To:1': 0.27; 'tried': 0.27; 'appear': 0.29; "doesn't": 0.30; 'statement': 0.30; 'gives': 0.31; 'code': 0.31; 'comments': 0.31; 'multiline': 0.31; 'writes:': 0.31; 'allows': 0.31; 'text': 0.33; 'says': 0.33; 'comment': 0.34; "can't": 0.35; 'but': 0.35; 'there': 0.35; 'doing': 0.36; 'subject:?': 0.36; 'url:org': 0.36; 'error.': 0.37; 'ben': 0.38; 'to:addr:python- list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'tell': 0.60; 'matter': 0.61; 'provide': 0.64; 'subject:. ': 0.67; 'invalid': 0.68; '\xe2\x80\x93': 0.77; "'true'": 0.84; 'comment.': 0.84; 'received:125': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ben Finney Subject: Re: A simple single line, triple-quoted comment is giving syntax error. Why? Date: Thu, 19 Mar 2015 11:06:55 +1100 References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: jigong.madmonks.org X-Public-Key-ID: 0xAC128405 X-Public-Key-Fingerprint: 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-pubkey.asc X-Post-From: Ben Finney User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) Cancel-Lock: sha1:oZY+fvEebmyq49ACZu2HPsHsoAg= X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.19 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 41 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1426723608 news.xs4all.nl 2893 [2001:888:2000:d::a6]:41003 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:87711 Aditya Raj Bhatt writes: > I always do single line comments with # but just for the sake of it I > tried it with ''' ''' and it gives me a syntax error. The only comment syntax in Python code is the line-end ‘# …’ syntax. > In both the interpreter, and the source code text file, doing - > > a = 5 '''a comment''' There is no comment on that line. You have an assignment statement immediately followed by a string literal, which is invalid syntax. > http://stackoverflow.com/questions/397148/why-doesnt-python-have-multiline-comments > which says that there are no 'true' multiline comments in python and > that all those 'block' comments are actually triple-quoted strings. That's correct. > So can someone tell me why a triple-quoted string gives a syntax error > if only in one line? Because the string literal – it doesn't matter how it's quoted – can only appear where the syntax allows for a string literal. It isn't a comment, so it can't be freely substituted for a comment. > Can someone also provide a sort of a 'guide' to triple-quoted comments > in general? The guide is simple: There are no triple-quoted comments in Python. If you triple-quote a string literal, it is still a string literal and must follow all the syntax rules for string literals. -- \ “[The RIAA] have the patience to keep stomping. They're playing | `\ whack-a-mole with an infinite supply of tokens.” —kennon, | _o__) http://kuro5hin.org/ | Ben Finney