Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7799337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:16:36+00:00 2026-06-02T00:16:36+00:00

Two of these statements run while the other fails with a syntax error. What

  • 0

Two of these statements run while the other fails with a syntax error. What am I doing wrong?

>>> Timer('for i in xrange(10): oct(i)').repeat(3)
[2.7091379165649414, 2.6934919357299805, 2.689150094985962]
>>> Timer('n = [] ; n = [oct(i) for i in xrange(10)]').repeat(3)
[4.0500171184539795, 3.6979520320892334, 3.701982021331787]
>>> Timer('n = [] ; for i in xrange(10): n.append(oct(i))').repeat(3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/timeit.py", line 136, in __init__
    code = compile(src, dummy_src_name, "exec")
  File "<timeit-src>", line 6
    n = [] ; for i in xrange(10): n.append(oct(i))
               ^
SyntaxError: invalid syntax
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T00:16:40+00:00Added an answer on June 2, 2026 at 12:16 am

    Your failing statement is syntactically incorrect. If you need to time multiple statement’s define it in a function and call Timer, after importing the function from main

    >>> def foo():
        n = []
        for i in xrange(10): n.append(oct(i))    
    
    >>> Timer("foo()","from __main__ import foo")
    

    Now you need to understand why the failing statement is incorrect

    Excerpt from the docs for Compound Statement

    A suite can be one or more semicolon-separated simple statements on the same line as the header, following the header’s colon, or it can be one or more indented statements on subsequent lines.

    stmt_list     ::=  simple_stmt (";" simple_stmt)* [";"]
    

    and similarly, a simple statement is

    simple_stmt ::=  expression_stmt
                     | assert_stmt
                     | assignment_stmt
                     | augmented_assignment_stmt
                     | pass_stmt
                     | del_stmt
                     | print_stmt
                     | return_stmt
                     | yield_stmt
                     | raise_stmt
                     | break_stmt
                     | continue_stmt
                     | import_stmt
                     | global_stmt
                     | exec_stmt
    

    It should now be clear to you when a semi-colon can (not should) be used.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Do these two statements pass the same type of argument (a Hash) to the
Which of these two statements is faster/better practice? myList.Where(x => { bool itemOne= x.ItemOne
I have these two statements : printf(%u,a+1); and printf(%u,(int *)a+1); Actually I was working
Is there any difference between these two LINQ statements: var query = from a
How do I combine these two select statements into one query: SELECT SUM( incidents
If I run the two statements in batch will they return one table to
While researching the use of Table Hints , I came across these two questions:
So I've these two statements: string insertUserData = INSERT INTO W711_User_Data(Network_ID, F_Name, M_Name, L_NAME,
I need to merge two SELECT statements. There are two tables in my database,
Given these two queries: Select t1.id, t2.companyName from table1 t1 INNER JOIN table2 t2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.