Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #8493 > unrolled thread

Python basic program problem

Started byAmaninder Singh <asingh0412@gmail.com>
First post2011-06-27 00:05 -0700
Last post2011-06-27 22:28 +0100
Articles 5 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  Python basic program problem Amaninder Singh <asingh0412@gmail.com> - 2011-06-27 00:05 -0700
    Re: Python basic program problem Noah Hall <enalicho@gmail.com> - 2011-06-27 08:18 +0100
    Re: Python basic program problem Daniel Kluev <dan.kluev@gmail.com> - 2011-06-27 18:19 +1100
    Re: Python basic program problem Andrew Berg <bahamutzero8825@gmail.com> - 2011-06-27 02:24 -0500
    Re: Python basic program problem Noah Hall <enalicho@gmail.com> - 2011-06-27 22:28 +0100

#8493 — Python basic program problem

FromAmaninder Singh <asingh0412@gmail.com>
Date2011-06-27 00:05 -0700
SubjectPython basic program problem
Message-ID<c07a7df7-0e26-4884-a237-cc0a1f148056@q14g2000prh.googlegroups.com>
Hi,
I am fairly new to python, I am trying to write simple code and It is
giving me syntax error. I am reading a book and following the
directions as it says in the book but I am not sure why it is not
working. Please guide me through. Any help appreciated.
>>> x = 2
>>> if x == 2:
   print "This is a test"

SyntaxError: invalid syntax
>>> if x == 2:
	   print "This is a test"

SyntaxError: invalid syntax
>>> x = 2
>>> if x = 2:

SyntaxError: invalid syntax
>>> if x == 2:
	print "This is test"

SyntaxError: invalid syntax
>>> Type "copyright", "credits" or "license()" for more information.
SyntaxError: invalid syntax
>>>
>>>
>>> print "this is a test"
SyntaxError: invalid syntax
>>> import keyword
>>> print keyword.kwlist
SyntaxError: invalid syntax
>>> print "hellow world"
SyntaxError: invalid syntax
>>> print 'hellow world'
SyntaxError: invalid syntax
>>>

[toc] | [next] | [standalone]


#8494

FromNoah Hall <enalicho@gmail.com>
Date2011-06-27 08:18 +0100
Message-ID<mailman.438.1309159116.1164.python-list@python.org>
In reply to#8493
On Mon, Jun 27, 2011 at 8:05 AM, Amaninder Singh <asingh0412@gmail.com> wrote:
> Hi,
> I am fairly new to python, I am trying to write simple code and It is
> giving me syntax error. I am reading a book and following the
> directions as it says in the book but I am not sure why it is not
> working. Please guide me through. Any help appreciated.
>>>> x = 2
>>>> if x == 2:
>   print "This is a test"
>
> SyntaxError: invalid syntax
>>>> if x == 2:
>           print "This is a test"
>
> SyntaxError: invalid syntax
>>>> x = 2
>>>> if x = 2:
>
> SyntaxError: invalid syntax
>>>> if x == 2:
>        print "This is test"
>
> SyntaxError: invalid syntax
>>>> Type "copyright", "credits" or "license()" for more information.
> SyntaxError: invalid syntax
>>>>
>>>>
>>>> print "this is a test"
> SyntaxError: invalid syntax
>>>> import keyword
>>>> print keyword.kwlist
> SyntaxError: invalid syntax
>>>> print "hellow world"
> SyntaxError: invalid syntax
>>>> print 'hellow world'
> SyntaxError: invalid syntax
>>>>
Looks like you're using the 3.x version, while your guide is 2.x. I
suggest you download the 2.x version, or find a new tutorial.

HTH

[toc] | [prev] | [next] | [standalone]


#8495

FromDaniel Kluev <dan.kluev@gmail.com>
Date2011-06-27 18:19 +1100
Message-ID<mailman.439.1309159175.1164.python-list@python.org>
In reply to#8493
On Mon, Jun 27, 2011 at 6:05 PM, Amaninder Singh <asingh0412@gmail.com> wrote:
>>>> print "this is a test"
> SyntaxError: invalid syntax

Most likely, you are running python 3.x, while reading python 2.x book.
In python 3.x print is now ordinary function,

>>> print('hello world')
hello world


In future, please include full tracebacks and python version info.

-- 
With best regards,
Daniel Kluev

[toc] | [prev] | [next] | [standalone]


#8496

FromAndrew Berg <bahamutzero8825@gmail.com>
Date2011-06-27 02:24 -0500
Message-ID<mailman.440.1309159473.1164.python-list@python.org>
In reply to#8493
On 2011.06.27 02:05 AM, Amaninder Singh wrote:
> Hi,
> I am fairly new to python, I am trying to write simple code and It is
> giving me syntax error. I am reading a book and following the
> directions as it says in the book but I am not sure why it is not
> working.
Looks like the book you're reading is outdated and refers to Python 2.
In Python 3, print is a function:
print('Hello there')

[toc] | [prev] | [next] | [standalone]


#8516

FromNoah Hall <enalicho@gmail.com>
Date2011-06-27 22:28 +0100
Message-ID<mailman.464.1309210580.1164.python-list@python.org>
In reply to#8493
On Mon, Jun 27, 2011 at 11:18 PM, Amaninder Singh <asingh0412@gmail.com> wrote:
> Yes, I think I am using 3.0 version. So how much difference is in between these two?
> On Jun 26, 2011, at 11:18 PM, Noah Hall wrote:
>> On Mon, Jun 27, 2011 at 8:05 AM, Amaninder Singh <asingh0412@gmail.com> wrote:
>>> Hi,
>>> I am fairly new to python, I am trying to write simple code and It is
>>> giving me syntax error. I am reading a book and following the
>>> directions as it says in the book but I am not sure why it is not
>>> working. Please guide me through. Any help appreciated.
>> Looks like you're using the 3.x version, while your guide is 2.x. I
>> suggest you download the 2.x version, or find a new tutorial.


Well, quite a lot. Read this -
http://wiki.python.org/moin/Python2orPython3 to get a better picture.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web