FAQ: Learn Python – Lists and Functions – Printing out a list item by item in a function


#1

This community-built FAQ covers the “Printing out a list item by item in a function” exercise in Codecademy’s lessons on Python.

FAQs for the Codecademy Python exercise Printing out a list item by item in a function:

Join the Discussion. We Want to Hear From You!

Have a new question or can answer someone else’s? Reply (reply) to an existing thread!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources about Python in general? Go here!

Want to take the conversation in a totally different direction? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account, billing, Pro, or Pro Intensive? Reach out to our support team!

None of the above? Find out where to ask other questions here!


#2

Other FAQs

The following are links to additional questions that our community has asked about this exercise:

  • This list will contain other frequently asked questions that aren’t quite as popular as the ones above.
  • Currently there have not been enough questions asked and answered about this exercise to populate this FAQ section.
  • This FAQ is built and maintained by you, the Codecademy community – help yourself and other learners like you by contributing!

Not seeing your question? It may still have been asked before – try (search) in the top-right of this page. Still can’t find it? Ask it below by hitting the reply button below this post (reply).


#3

7 posts were split to a new topic: List index out of range


#4

why this function has no return?


#5

It does not need a return, since it has nothing to return. The purpose is in the name, print_list, which is the operation the function performs.


#6

so we should not necessarily return sth in defining a function?


#7

Functions are a way of composing a piece of useful code that can be re-used over and over with variable parameters to produce an expected result given the inputs. Some functions do not act upon the data, but simply output it, or report it. Their job, as in the above case is over and done once the function has run. No states are changed. They have no effect on the data.

function add_ab(a, b) {
    return a + b;
}

The above function also does not affect any data, but simply reports a sum of two data points, which are returned so the sum can be carried forward in other program operations, as needed…

function add_list_item(lst, item) {
    lst.append(item);
}

The above does affect the data since the inputed list has had a new value added to it. It does not need to return the list since it already exists outside of the function. lst is merely a reference to that list which could be any list under any name.

In time, this will all make perfect sense once you have more experience and new concepts under your belt.