Python Forum
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List in function
#1
def f(x,l=):
for i in range(x):
l.append(i*i)
print(l)

f(2)
f(3,[3,2,1])
f(3)


[0, 1]
[3, 2, 1, 0, 1, 4]
#How this is possible?
[0, 1, 0, 1, 4]
Please explain
Reply
#2
see
http://docs.python-guide.org/en/latest/writing/gotchas/
https://pythonconquerstheuniverse.wordpr...arguments/
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I created a function that generate a list but the list is empty in a new .py file mrhopeedu 2 2,246 Oct-12-2019, 08:02 PM
Last Post: mrhopeedu

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020