Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using print as a variable name in python [duplicate]

Tags:

python

While following a tutorial for python, I got to know that we can use print for a variable name, and it works fine. But after assigning the print variable, how do we get back the original print function?

>>> print("Hello World!!")
Hello World!!!
>>> print = 5
>>> print("Hi")

Now, the last call gives the error TypeError: 'int' object is not callable, since now print has the integer value 5.

But, how do we get back the original functionality of print now? Should we use the class name for the print function or something? As in, SomeClass.print("Hi")?

Thanks in advance.

like image 338
albin Avatar asked Nov 28 '22 09:11

albin


1 Answers

>>> print = 5
>>> print = __builtins__.print
>>> print("hello")
hello
like image 100
Tim Pietzcker Avatar answered Dec 05 '22 15:12

Tim Pietzcker