My if statement keeps returning 'None' for empty list
<p>I'm a beginner at coding in Python and I've been practising with exercises CodeWars.</p>

<p>There's this exercise which basically wants you to recreate the display function of the "likes" on Facebook, i.e. how it shows the number likes you have on a post etc.</p>

<p>Here is my code:</p>

<pre><code>def likes(names):
    for name in names:
        if len(names) == 0:
           return 'no one likes this'
        elif len(names) == 1:
           return '%s likes this' % (name)
        elif len(names) == 2:
           return '%s and %s like this' % (names[0], names[1])
        elif len(names) == 3:
           return '%s, %s and %s like this' % (names[0], names[1], names[2])
        elif len(names) &gt;= 4:
           return '%s, %s and %s others like this' % (names[0], names[1], len(names) - 2)

print likes([])
print likes(['Peter'])
print likes(['Alex', 'Jacob', 'Mark', 'Max'])
</code></pre>

<p>This prints out:</p>

<pre><code>None
Peter likes this
Alex, Jacob and 2 others like this
</code></pre>

<p>My main issue here is that my first 'if' statement is not producing the string 'no one likes this' for when the argument: [] is empty. Is there a way around this problem?</p>

<p>The for loop that you have done occurs one time for each element of the list, but you do non have elements in the list, so the loop won't occour, and the return value will be "None"</p>

<pre><code>def likes(names):
    #for name in names:  #LOOK HERE: you definetly not need this loop
    if len(names) == 0:
       return 'no one likes this'
    elif len(names) == 1:
       return '%s likes this' % (names[0])
    elif len(names) == 2:
       return '%s and %s like this' % (names[0], names[1])
    elif len(names) == 3:
       return '%s, %s and %s like this' % (names[0], names[1], names[2])
    elif len(names) &gt;= 4:
       return '%s, %s and %s others like this' % (names[0], names[1], len(names) - 2)
</code></pre>

python list function if-statement