10

Is print a built-in function? If it is, why I cannot run dir(print)? dir is a built-in function and dir(dir) works well. So it looks very strange to me that dir(print) could not work.

1 Answer 1

16

In python 2 print is a statement and not a function and you can't put a statement as a function argument, in the other hand in python3 print is a function so you can do dir(print).

Sign up to request clarification or add additional context in comments.

1 Comment

In Python 2.6 and later you can do from __future__ import print_function first to get the same behavior.

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.