Return last character of string in python
<p>I want to print the last character of string in python reading from the file. I am calling as <code>str[-1]</code> But not working. </p>

<p><strong>t.txt contains</strong></p>

<pre><code>Do not laugh please!        9

Are you kidding me?     4
</code></pre>

<p>My code is </p>

<pre><code>with open('t.txt', 'r') as f:
            for line in f:
                print(line )
                print(line[-1])
                #break
</code></pre>

<p>But it is not printing anything. </p>

<p>Simple take the string and clear it's leading and trailing spaces. Then return the last character in your case. Otherwise simply return last character.</p>

<pre><code>line=line.strip()
return line[-1]
</code></pre>

python