Python was doing well, but I'm suddenly asking you an invalid Syntax error

Asked 1 years ago, Updated 1 years ago, 82 views

Hello! I'm Parin, who started studying Python.

I opened it again to review the files I made last weekend Last weekend, when I did CMD-I, I could check it on the console without any problems

Suddenly, an InvalidSyntax error appears. Can I know the solution??


print('')
print ('separator option')
print('')
print('P', 'Y', 'T', 'H', 'O', 'N', sep='/')
print('010','7777','1234', sep='-')
print('python','google.com', sep=' @ ')

Error name:

line 20 print('P', 'Y', 'T', 'H', 'O', 'N', sep='/') ^ SyntaxError: invalid syntax

invalid

2022-09-20 20:51

1 Answers

Isn't it the Python version? If you have both versions installed, please check the environment variable settings.

The Python 2.7 version does not support the sep keyword. If you write "from_future_ import print_function" on the first line, it will work.

#python 2.7.15
from __future__ import print_function
import sys
print(sys.version)
print('')
print ('separator option')
print('')
print('P', 'Y', 'T', 'H', 'O', 'N', sep='/')
print('010','7777','1234', sep='-')
print('python','google.com', sep=' @ ')
#python 3.7.1
import sys
print(sys.version)
print('')
print ('separator option')
print('')
print('P', 'Y', 'T', 'H', 'O', 'N', sep='/')
print('010','7777','1234', sep='-')
print('python','google.com', sep=' @ ')

Please check it out.

Thank you.


2022-09-20 20:51

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.