-2

I have used print to store value like:

print=3

After then I am not able to use it to print any message:

print('a message')

Its giving error:

'int object is not callable'

Is there any way to use print both as a variable and a functions? If not then Why not python just makes built-in function names as keyword to remove this conflict?

Rishabh
  • 391
  • 3
  • 13

1 Answers1

1

Functions and data share the same namespace in Python -- as they do in many other languages (the entire family of LISP-1s comes to mind first, including Scheme and Clojure; also Ruby, Groovy, and I'm sure many more).

Thus no, you cannot do this. Widely available checkers (pylint, pychecker, etc) will catch and report on attempts to shadow builtins (such as print) with data.

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441