-1

Why does this code return None?

 def html_list(inputs_list):
    print("<ul>")

    for html in inputs_list:
        html = ("<li>" + html + "</li>")
        print(html)

    print("</ul>")

bam = ['boom','bust']

print(html_list(bam))
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • What do you expect it should return and why? – juanpa.arrivillaga Jan 27 '18 at 21:58
  • This is what i'm trying resolve.Write the html_list function. The function takes one argument, a list of strings, and returns a single string which is an HTML list. For example, if the function should produce the following string when provided the list ['first string', 'second string'].
    • first string
    • second string
    That is, the string's first line should be the opening tag
      . Following that is one line per element in the source list, surrounded by
    • and
    • tags. The final line of the string should be the closing tag
    .
    – Richard Pak Jan 28 '18 at 08:12

1 Answers1

0

Your function has print calls within it, but does not return anything. If a function completes without returning, it really returns None.

This means that if you call the function inside a print statement, it will run, do the prints within the function, but return None which will then get passed into the print() function - so this is why you get the intended output and then a "None" at the end.

You can also see this through a more simple example:

>>> def f():
...     print("inside f")
... 
>>> print(f())
inside f
None
Joe Iddon
  • 20,101
  • 7
  • 33
  • 54