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:
"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?
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
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 =]
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.![]()
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
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.
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
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks