Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1a.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.017 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'string.': 0.04; 'error:': 0.05; 'python': 0.11; 'syntax': 0.13; 'output': 0.15; 'iterator': 0.16; 'run:': 0.16; 'syntaxerror:': 0.16; 'wrote:': 0.16; 'string': 0.17; 'copied': 0.18; 'version.': 0.18; 'language': 0.19; 'email addr:gmail.com>': 0.20; '(on': 0.22; 'assuming': 0.22; '2015': 0.23; 'specified': 0.23; 'header:In-Reply-To:1': 0.24; 'tim': 0.24; 'message-id:@mail.gmail.com': 0.28; 'coded': 0.29; 'colon': 0.29; 'e.g.': 0.31; 'to:name:python-list': 0.31; 'print': 0.31; 'url:python': 0.33; 'subject:use': 0.33; 'received:google.com': 0.34; 'to:addr:python-list': 0.35; 'something': 0.35; 'but': 0.36; 'url:org': 0.36; 'statement': 0.36; 'hi,': 0.37; 'subject:: ': 0.37; 'end': 0.39; 'means': 0.39; 'url:2': 0.39; 'does': 0.39; 'url:docs': 0.39; 'to:addr:python.org': 0.39; 'url:3': 0.60; 'back': 0.61; 'hope': 0.61; 'per': 0.61; 'above,': 0.63; 'complete': 0.63; 'delaney': 0.84; 'url:tutorial': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=AFqgsj51IRIgX+cWhDLXyuFtTP7Bvej9f6mRL+S4MCc=; b=1C/tPFN4T0pidI0J75NB8WMYJBpFGy1khphA0m7cslqU+F84wiae/ZfwmLirX8s9oN +nuWF9EZ/R2QTevncCOdV/7lG8ZYh/Yg1pc/aknhTSy7gio73TnXP6+0dN5K6Wd8+NY/ m0A+GqdJB8V2tjJo+PAlDUL4N1PXkFTD/MD1I5k/s5NOy1GE+aicU5Q7zdBrS576ns++ g/AKy0dZHhtTUQng4ZVecCRwR9EStAGMZugCS5npPaO6igI1aS3s4yLZSziW3vgABbH9 gzPjF5gBX4U3BU/2s5gChpnxkiCvLrnUarKGgM4CmPj0zPxRbPTWlI6zvQXg6x9C/Ev1 XIiw== MIME-Version: 1.0 X-Received: by 10.181.11.137 with SMTP id ei9mr15067016wid.48.1433114582240; Sun, 31 May 2015 16:23:02 -0700 (PDT) In-Reply-To: <514c05fc-dded-4278-ac86-3e8e3cd0e851@googlegroups.com> References: <514c05fc-dded-4278-ac86-3e8e3cd0e851@googlegroups.com> Date: Mon, 1 Jun 2015 09:23:02 +1000 Subject: Re: What use for reversed()? From: Tim Delaney To: Python-List Content-Type: multipart/alternative; boundary=f46d043892d798d2ff051768fd78 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 80 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1433114589 news.xs4all.nl 2845 [2001:888:2000:d::a6]:35845 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:91599 --f46d043892d798d2ff051768fd78 Content-Type: text/plain; charset=UTF-8 On 1 June 2015 at 05:40, fl wrote: > Hi, > > I have a string b='1234'. I run: br=reversed(b) > > I hope that I can print out '4321' by: > > for br in b > > but it complains: > SyntaxError: invalid syntax > Any time you get a SyntaxError, it means that you have coded something which does not match the specified syntax of the language version. Assuming you copied and pasted the above, I can see an error: for br in b The for statement must have a colon at the end of line e.g. a complete for statement and block is: for br in b: print br This will output the characters one per line (on Python 3.x), since that is what the reversed() iterator will return. You will need to do something else to get it back to a single string. Have you read through the python tutorials? https://docs.python.org/3/tutorial/ or for Python 2.x: https://docs.python.org/2/tutorial/ Tim Delaney --f46d043892d798d2ff051768fd78 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
On 1= June 2015 at 05:40, fl <rxjwg98@gmail.com> wrote:
Hi,

I have a string b=3D'1234'. I run: br=3Dreversed(b)

I hope that I can print out '4321' by:

for br in b

but it complains:
SyntaxError: invalid syntax

Any time yo= u get a SyntaxError, it means that you have coded something which does not = match the specified syntax of the language version.

Assuming you copied and pasted the above, I can see an error:
<= br>
=C2=A0 =C2=A0 for br in b

The fo= r statement must have a colon at the end of line e.g. a complete for statem= ent and block is:

for br in b:
=C2=A0 = =C2=A0 print br

This will output the characters on= e per line (on Python 3.x), since that is what the reversed() iterator will= return. You will need to do something else to get it back to a single stri= ng.

Have you read through the python tutorials?


or for Pyt= hon 2.x:


Tim Delaney=C2=A0
--f46d043892d798d2ff051768fd78--