separator - Python 3.3: separation argument (sep) giving an error -


i new programming , i'm starting out python. tried question here didn't find anything.

i'm trying work simple print command i'm getting error reason don't understand.

last = 'smith' middle = 'paul' first = 'john' print(first.capitalize(), middle.capitalize(), last.capitalize(), sep='\t') 

according answer in book, should right, every time try run it, error 'sep':

print(first.capitalize(), middle.capitalize(), last.capitalize(), sep='\t')                                                                      ^ syntaxerror: invalid syntax 

can tell me i'm doing wrong. it's worth i'm using pyscripter.

[edit]

thanks that. found out i'm using python 2.7.3 instead of 3.3. looked manual see how separator works. seems me difference square bracket. manual describes print function :

print([object, ...][, sep=' '][, end='\n'][, file=sys.stdout])  

so changed print command , added square bracket:

print ([first.capitalize(),middle.capitalize(),last.capitalize()] [, sep='\t']) 

but unfortunately doesn't work either error highlights square brackets around sep='\t'. when take brackets out, error doesn't go away.

i'm not sure i'm doing wrong, seems should simple.

you aren't using python 3, think are. try:

import sys print(sys.version) 

and see comes out. python 2 print ... statement (not print(...) function in python 3) interprets

print (first.capitalize(), middle.capitalize(), last.capitalize(), sep='\t') 

which trying print tuple keyword argument, syntax error on sep


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -