D
D
deleted-Alex2222014-01-28 21:17:47
Python
deleted-Alex222, 2014-01-28 21:17:47

When does IDLE do an implicit print?

When I type "f=func()" in IDLE (Py 2.7), that's exactly what happens. If I enter something as simple as "2+3" then "print(2+3)" is actually executed. I want to do the same for myself (almost a python console).
In what cases it is necessary to do implicit print? maybe just when there is no equal sign in the command? and/or no brackets?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
deleted-Alex222, 2014-01-28
@deleted-Alex222

They answered me on SO. The answer is - if the result of the expression (which was entered in >>>) is not None, then IDLE prints it. The same should be done for me.

L
leclecovich, 2014-01-28
@leclecovich

When you type 2+3 and press Enter, the expression is evaluated. If you do not assign the result of an expression to a variable in the interactive console, then it (the result) will be displayed on the screen.
This is only true for the interactive console. If you write 2 + 3 in the script, then you will not see the result.
Every class has a __str__(self) method. It is the one that is called when you press Enter in IDLE or do a print; may be overridden.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question