Python Forum
I can't understand this problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I can't understand this problem
#1
So sorry, I'm a beginner with programming and I face something in lists confused me.
I know that when I concatenate 2 lists with (+) I create a new list.
I'm using Python 2.7

list1 = [1,2,3]
list1 = list1 + [4,5]
print list1
here I get list1 = [1,2,3,4,5]
but where I put this in a procedure I don't get the same result
list2 = [3,4,5]
def mylist(my_list):
    my_list = my_list + [6,7]
mylist(list2)
print list2
here I get list2 = [3,4,5]
Why that?
another question why I get "none" message when I try to print
print mylist(list2)
. What is the difference between calling the procedure then print it
mylist(list2)
print list2

and print directly the procedure
print mylist(list2)
Reply


Messages In This Thread
I can't understand this problem - by muhammedkhairy - Dec-23-2018, 07:37 PM
RE: I can't understand this problem - by ichabod801 - Dec-23-2018, 08:36 PM
RE: I can't understand this problem - by stullis - Dec-23-2018, 09:35 PM
RE: I can't understand this problem - by ichabod801 - Dec-23-2018, 09:44 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Couldn't really understand the problem Batselot 1 2,301 Dec-13-2018, 07:59 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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