Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I tell new Python to use the old print

The print function's syntax has been changed in newer versions of python. The problem is that at home, I have the newer version of python while at office the old one. How can I have the same program run on both the newer and old python versions?

like image 754
MetallicPriest Avatar asked Sep 30 '13 21:09

MetallicPriest


People also ask

How do I replace an old print statement in Python?

Summary: The most straightforward way to overwrite the previous print to stdout is to set the carriage return ( '\r' ) character within the print statement as print(string, end = "\r") .

How do you print without newline in Python?

The new line character in Python is \n . It is used to indicate the end of a line of text. You can print strings without adding a new line with end = <character> , which <character> is the character that will be used to separate the lines.

How is print different in Python 3?

Question: What is the difference between print in Python 2 and 3? Answer: In Python 2, print is treated as a statement whereas, in Python 3, print is treated as a function. Hence, we do not need to wrap the text to be printed in parentheses, although we can if we want.

Does Python 3 support print?

The print statement is gone in Python 3; the compiler doesn't support it anymore. This will remove support for the print statement in Python 2 just like it is gone in Python 3, and you can use the print() function that ships with Python 2.


1 Answers

If you're using iPython/ Jupyter, run

%autocall 1

After that, you can use

print "yo"

like in Python 2.

like image 139
Felix Avatar answered Sep 24 '22 15:09

Felix