Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why cannot pass print function to dir() in python?

Tags:

python

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.

like image 346
Thomson Avatar asked Sep 19 '11 14:09

Thomson


1 Answers

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).

like image 147
mouad Avatar answered Oct 06 '22 15:10

mouad