What is reason for syntax error of print statement of given python code [closed]

给你一囗甜甜゛ 提交于 2019-12-02 13:43:16

The single quote used in the print statement is ' with ascii value 39.

>>> ord("'")
39

The one used in the print statement in the question is not a quote ' but RIGHT SINGLE QUOTATION MARK' (U+2019)

>>> u"’"
u'\u2019'

Since, you are using python 2, to use sep in the print statement you need to import the functionality from the future.

from __future__ import print_function
print('The sum of ', x, ' and ', y, ' is ', x+y, '.', sep='')

It's because of those wacky quote characters like . Change them to ' characters and you should not have any problem.

First, replace the by '

Second, you may need to add one more sentence: from __future__ import print_function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!