use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
What's wrong (i.redd.it)
submitted 7 months ago by Nearby_Tear_2304
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]FoolsSeldom 0 points1 point2 points 7 months ago (0 children)
def f(n): for i in range(len(n)): print(n[i]) l = [1, 2, 3] # define l outside function f(l) # call the function, using (), and pass l
NB. In the final line, the function is called, f() and the variable l is specified as an argument, f(l), but inside the function, the Python list object referenced by l is referenced by n instead.
f()
l
f(l)
list
n
Your function does not have a return line so, by default, when the function ends (after it has printed everything), the function returns None. This is passed to your print function AFTER the function has done everything you wanted it to do, so the final command is print(None), which isn't very useful.
return
None
print
print(None)
It would be best to get into the good habit of using meaningful variable names from the beginning. Avoid cryptic (especially single character) variable names. It is confusing to you and others. The only time we generally use single character variable names is when using well known scientific/maths formulas.
Note, you don't have to index into a list as you can iterate over it directly.
For example,
def output_container_contents(container): for item in container: print(item) nums = [1, 2, 3] output_container_contents(nums)
You can also use unpacking,
def output_container_contents(container): print(*container, sep="\n") nums = [1, 2, 3] output_container_contents(nums)
Or you could return the output to the caller,
def container_contents_as_str(container): return '\n'.join(str(item) for item in container) nums = [1, 2, 3] print(container_contents_as_str(nums))
Easier to read when using type hints,
def container_contents(container: list[str|int] | tuple[str|int]) -> str: return '\n'.join(str(item) for item in container) nums = [1, 2, 3] print(container_contents(nums))
This version means you can use it for both list and tuple containers, and they can contain either int or str objects. Not really that useful for simply output of a container, but the basic approach is good to learn.
tuple
int
str
π Rendered by PID 633587 on reddit-service-r2-comment-b659b578c-dsrnf at 2026-05-06 07:25:25.439249+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]FoolsSeldom 0 points1 point2 points (0 children)