Basic python usage, calling a function
<p>I am working on leetcode but actually never wrote a file locally before. </p>

<pre><code>class Solution(object):
    def singleNumber(self, nums):

        for i in range(0,len(nums),2):
            if (i != len(nums) - 1) and (nums[i] != nums[i+1]):
                print (nums[i])
            elif i == len(nums) - 1:
                print (nums[i])

    def main():
        nums=[1,1,2,2,3]
        s=Solution()
        s.singleNumber(nums)
        print('done')
</code></pre>

<p>I am running this script but not seeing any output and don't understand what I'm doing wrong.</p>

<p>Unlike many other programming languages, such as Java, Python does not require the <code>main</code> method to be inside a class. Even more, Python <strong>does not need to have a <code>main</code> method defined</strong>: it runs the whole file as an application. In your original post, Python performs this actions:</p>

<ul>
<li>Define the method <code>singleNumber</code> as the code it holds.</li>
<li>Define the method <code>main</code> as the code it holds.</li>
<li>Save this two methods inside the class <code>Solution</code>.</li>
<li>No more lines to run, therefore ends application.</li>
</ul>

<p>To make the application correct, you must write it as follows:</p>

<pre><code>class Solution(object):
    def singleNumber(self, nums):
        for i in range(0,len(nums),2):
            if (i != len(nums) - 1) and (nums[i] != nums[i+1]):
                print (nums[i])
            elif i == len(nums) - 1:
                print (nums[i])

if __name__=='__main__':
    nums=[1,1,2,2,3]
    s=Solution()
    s.singleNumber(nums)
    print('done')
</code></pre>

<p>You may wonder why the line <code>if __name__=='__main__':</code>; every file contains the variable <code>__name__</code> implicitly defined and its value depends if you're running the file directly or it is imported. On the first case, the assignment <code>__name__='__main__'</code> is done, on the second case the <code>__name__</code> variable is assigned the name of the file itself; this gives you an idea whether this file is the main or not.</p>

<p>You may also discard the <code>Solution</code> class and promote the <code>singleNumber</code> method to a module method.</p>

python