-3

Possible Duplicate:
python print end=' '

Hello I've been teaching myself python, and I'm having trouble with the end= " " statement. could anybody help me with it?when i run it in my code it said that is is a invalid syntax. Thx in advance. Am i writing it wrong?

Help for a newbie is greatly appreciated.

Community
  • 1
  • 1
Kbob1998
  • 77
  • 1
  • 1
  • 6

2 Answers2

3

I assume that you are having trouble with print statement, So you are trying to use print(var,end=""). This syntax is only valid with Python 3.0. if you are using Python 2.x then it will show you an error. In order to know which version of python you are using type python --version in your terminal. Python 2.x and python 3 slightly differ in syntax. You can Read the the difference between them here. By the way in Python 2.x you can achieve the same result by print var,

Sreenath Nannat
  • 1,949
  • 1
  • 13
  • 18
1

Clearly not a problem with an assignment:

pax@pax-desktop:~$ python
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24) 
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> end= " "
>>> len(end)
1
>>> 

Therefore there must be another issue. Short of seeing the error message and actual code, the only suggestions I can make are:

  • Check indentation. Python is notoriously picky about this since it's how it decides what blocks of code are.
  • Check that the quote marks are the regular ones, not something like “ ” cut'n'pasted from a Word document or web page.

That last one is particularly annoying when web page creators can't be bothered posting proper code (or their presentation engines munge it) and, on my system, results in:

pax@pax-desktop:~$ python
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24) 
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> end= “ ”
  File "<stdin>", line 1
    end= “ ”
         ^
SyntaxError: invalid syntax
paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
  • Looking at the title of the question, I suspect "smart" quotes are the issue. – johnsyweb Oct 22 '11 at 01:03
  • @Johnsyweb - I'm not so sure - check [this](http://meta.stackexchange.com/questions/109008/did-stackexchange-just-implement-smart-quotes) post out... – Nate Oct 22 '11 at 01:08