2013-07-02 21 views
2

我試圖去學習如何使用ascii功能在Python 3如何在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 

如何使用此功能?

+1

'print'在Python 3 – Blender

回答

4

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 
+2

好一個功能,是令人尷尬。謝謝! – sdasdadas