Invalid syntax on hello world program


Joined
Mar 11, 2011
Messages
1
Reaction score
0
Hi, i'm just starting to learn python obviously and trying to get this program to run and it comes back as invalid syntax.

Python 2.6.

Print 'hello world' works fine, but i wrote the following program in text wrangler

#!/usr/bin/python
# Filename : helloworld.py
print 'Hello World'

then opened up a terminal and typed python helloworld.py and it comes back as invalid syntax.

I'm a right beginner at all this but i've tried numerous different ways of writing it with brackets, quotes, double quotes, spaces etc., and i cant' get anything to work... nor can i seem to find a definitive answer in my search on what python 2.6 syntax is.

So basically i feel stuck with no being able to continue working through the guide until i can get this program working. Any help be great.
 
Ad

Advertisements

Joined
Jun 28, 2017
Messages
5
Reaction score
2
There have been some definite changes between Python 2.x and Python 3.x.
While you are in the Python 2.6 interpreter, your code works fine, but when you dropped into a terminal and
started python, you got python 3.x

so to be clear:
Python 2.x:
print 'Hello World'

Python 3.x:
print("Hello World")
Note the () in the print function.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top