Closed Thread
Results 1 to 7 of 7

Thread: Odd syntax error?

  1. #1
    akashhsaka is offline Newbie
    Join Date
    Apr 2009
    Posts
    4
    Rep Power
    0

    Odd syntax error?

    I'm just beginning programming and was told that Python is a great first language. So it's the basic, introduction program Hello, World. Seemingly very simple.

    print "Hello, world."

    End of the code.
    I'm using Python 3.0 and it gives me a very plain pop-up error stating an invalid syntax and highlights the latter quotation. I typed it out just like the book I'm using said to. Not sure what I'm doing wrong here. So I got the notion to do:

    print
    "Hello, world."


    I ran it and then the shell popped up and all it had to say was restart with a bunch of "=" on either side. I tried using:

    print 'Hello, world.'

    and it did the same thing as when I tried running it the second way, shell just popped up and said Restart then did nothing else. Any ideas?

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Apr 2009
    Location
    Trapped in my own little world.
    Posts
    2,487
    Rep Power
    33

    Re: Odd syntax error?

    I dont know python at all but from what I can tell you may try and put a semicolon at the end of the statement. That might help it.

    Not all languages require that - but if it doesnt I believe every statement must be on its own line so none of that two line stuff you have in that second code set.

    Python "Hello World" Tutorial - "Hello, World!": A Quick Tutorial on Python

  4. #3
    akashhsaka is offline Newbie
    Join Date
    Apr 2009
    Posts
    4
    Rep Power
    0

    Re: Odd syntax error?

    Yeah, python doesn't require semicolons, and as you saw in my previous post, I attempted to write the code exactly as shown in that tutorial link. In fact, I made more apparent progress (there was no syntax error) when I put the other bit of code onto the second line. The reason i did that is because I'd read somewhere that functions had to be on their own line or something to that effect. In any case, still accepting help. It would be appreciated =]

  5. #4
    _J_
    _J_ is offline Newbie
    Join Date
    May 2009
    Posts
    6
    Rep Power
    0

    Re: Odd syntax error?

    Which version of python are you using?
    I know I tried using version 3.0.1 or something and it didn't like print statements for some reason (perhaps a library needs to be added? Didn't actually work out why...)
    Try downloading Python 2.6.2 (the other current version) and try again. I had the same issue a while back when I accidently downloaded the wrong version but using version 2.6.2 worked for me.

    You can download Python from the homepage under the downloads tab

    Hope that helped.

  6. #5
    Join Date
    Oct 2008
    Posts
    4,060
    Blog Entries
    6
    Rep Power
    45

    Re: Odd syntax error?

    things are different in python 3 - you need to do it like:
    print('hello world')
    your book probably uses python 2, download that if you intend to learn from your book
    Posted via CodeCall Mobile

  7. #6
    manux's Avatar
    manux is offline Programming Professional
    Join Date
    Oct 2008
    Posts
    234
    Blog Entries
    1
    Rep Power
    14

    Re: Odd syntax error?

    in Python 3.0 print is a function and no longer a keyword, so you need to call print(argument). But most tutorials you will find on the internet or in books use Python 2.x I recommend you use 2.6 if you aren't used to python and feel like learning on the internet.

  8. #7
    PythonPower's Avatar
    PythonPower is offline Programming Professional
    Join Date
    Feb 2009
    Posts
    228
    Rep Power
    13

    Re: Odd syntax error?

    I'd recommend:

    Dive Into Python 3

    It might be a little over the head of someone new to programming entirely though. There's always the good ol' standard docs:

    The Python Tutorial - Python v3.0.1 documentation

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. C++ syntax error?
    By DMK741 in forum C and C++
    Replies: 10
    Last Post: 01-04-2011, 07:41 PM
  2. SQL syntax error
    By Timefly in forum PHP Development
    Replies: 2
    Last Post: 11-02-2010, 06:30 AM
  3. [help]Parse error: syntax error, unexpected $end
    By kiddies in forum PHP Development
    Replies: 3
    Last Post: 07-18-2010, 02:58 PM
  4. Possible Syntax Error.
    By ImTheMessenger in forum Python
    Replies: 3
    Last Post: 01-22-2010, 08:40 PM
  5. SQL syntax error
    By reachpradeep in forum Database & Database Programming
    Replies: 2
    Last Post: 10-11-2007, 09:29 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts