Is there a way to avoid a new line while using `end=`
<p>I've just started using python and I'm creating a simple program that will ask whoever the user is a question and then from the text file I will extract a specific line and print that line and along with the line - at the end I will add their answer. here's the code.</p>

<pre><code>    question = input("do you want to print the line")
    if "yes" in question:
        print(open("tp.txt").readlines()[:10][-1],end=question) 
</code></pre>

<p>The issue is that <code>,end=question)</code> puts the users answer on a new line. I know that <code>end=</code> is the same as <code>\n</code>. So I'm just wondering is there a way or an alternative to stop 'end=' from automatically creating a new line?</p>

<pre><code> print(open("tp.txt").readlines()[:10][-1],
</code></pre>

<p>is the way I open and read a specific line from the file
since its a 'nice' shortcut to do than rather do<code>with open (filename.txt,'r') as f:</code></p>

<p>The problem is that the lines returned by <code>readlines()</code> contain the ending newline:</p>

<pre><code>$ echo 'a
&gt; b
&gt; c
&gt; ' &gt; test_file.txt
$ python3
Python 3.5.2 (default, Jul  5 2016, 12:43:10) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; with open('test_file.txt') as f:
...     print(f.readlines())
... 
['a\n', 'b\n', 'c\n', '\n']
</code></pre>

<p>See the <code>\n</code>? Note the difference bewteen:</p>

<pre><code>&gt;&gt;&gt; print('a\n')
a

&gt;&gt;&gt;
</code></pre>

<p>And:</p>

<pre><code>&gt;&gt;&gt; print('a')
a
&gt;&gt;&gt;
</code></pre>

<p>So you want to remove that:</p>

<pre><code>&gt;&gt;&gt; with open('test_file.txt') as f:
...     for line in f:
...         print(line.rstrip('\n'), end='&lt;something&gt;')
... 
a&lt;something&gt;b&lt;something&gt;c&lt;something&gt;&lt;something&gt;&gt;&gt;&gt; 
</code></pre>

python python-3.5