2

I am attempting to learn how to use the ascii function in Python 3.

The documentation reads

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.

However, when I attempt to use print ascii("c") I receive the error:

print ascii("c")
          ^
SyntaxError: invalid syntax

How do I use this function?

1
  • 1
    print is a function in Python 3. Commented Jul 2, 2013 at 6:20

1 Answer 1

4

print is a function in python3, you're getting that error because you're trying to use it as a statement.

print (ascii("c"))

Demo:

>>> print (ascii("c"))
'c'
>>> print ascii("c")
  File "<ipython-input-3-c44db7d0eada>", line 1
    print ascii("c")
              ^
SyntaxError: invalid syntax
Sign up to request clarification or add additional context in comments.

1 Comment

Well that's embarrassing. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.