overwriting output of function in terminal on same line
<p>I have a function, for example</p>

<pre><code>def f(x):
    for i in range(x):
        print i
</code></pre>

<p>Without making any addition in f(x) function, is it possible to overwrite the  terminal line during run? For example, in my case it shows like this:</p>

<pre><code>print f(5)
</code></pre>

<p>output is:</p>

<pre><code>1
2
3
4
</code></pre>

<p>but I want it to overwrite and instead print like this:</p>

<pre><code>print f(5)

4
</code></pre>

<p>Please keep in mind that I cannot modify inside f(x) function.</p>

<p>If you are trying to print only the last line, you can pipe the output and use tail command to retrieve only the last word.</p>

<p>Useful link: <a href="https://kb.iu.edu/d/acrj" rel="nofollow">https://kb.iu.edu/d/acrj</a></p>

python python-2.7