我正在尝试学习如何在 Python 3 中使用 ascii
函数。
文档内容如下
ascii(object)
As repr(), return a string containing a printable representation of an object, but escape the non-ASCII characters in the string returned by repr() using \x, \u or \U escapes. This generates a string similar to that returned by repr() in Python 2.
但是,当我尝试使用 print ascii("c")
时,我收到错误:
print ascii("c")
^
SyntaxError: invalid syntax
如何使用此功能?
最佳答案
print
是 python3 中的一个函数,您收到该错误是因为您尝试将其用作语句。
print (ascii("c"))
演示:
>>> print (ascii("c"))
'c'
>>> print ascii("c")
File "<ipython-input-3-c44db7d0eada>", line 1
print ascii("c")
^
SyntaxError: invalid syntax
关于python - 如何在 Python 3 中使用 ascii 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17418681/