Home > other >  Python beginners problems
Python beginners problems

Time:10-26

Def make_great (magicians) :

For the name in magicians:

The magician='the Great' + name

Name=magician

Print (name)

Def show_magician (names) :

For magician in names:

Print (magician)

Magicians=[' John ', 'machel', 'jack']

Make_great (magicians)

Show_magician (magicians)


Why there is no change the original list?

CodePudding user response:

This code is not on the list for deletion, simply list the contents of the traversal string concatenation and printed

Is the feeling which block of code will change list?

CodePudding user response:

For the name in magicians:

The magician='the Great' + name

Name=magician
This won't be in the traverse the list of list elements to change?

CodePudding user response:

reference 1 floor Vv. Stone3 response:
this code is not to increase list of deleted, just list the contents of the traversal string concatenation and printed

Is the feeling which block of code will change list?

For the name in magicians:

The magician='the Great' + name

Name=magician
This won't be in the traverse the list of list elements to change?

CodePudding user response:


Print (' - '* 50)

Def make1 (magicArgs) :
Print (' function parameter list variable magicArgs in memory address: % s' % id (magicArgs))
I=0
The for m in magicArgs:
Print ()
Print (' first output iteration variable m memory address and by subscript access list elements of memory address, the result is the same ')
Print (' magicArgs element % I in memory address: % s' % (I, id (magicArgs [I])))
Print (' m variables in memory address: % s' % id (m))

Print ()
Print (' then change the variable m values')

M=m * 10
M: print (' % s' % m)
Print (' list1 [I] : % s' % list1 [I])
Print (' magicArgs element % I in memory address: % s' % (I, id (magicArgs [I])))
Print (' m variables in memory address: % s' % id (m))

I +=1


List1=[' 1 ', '2', '3',]
Print (' list variable list1 in memory address: % s' % (id (list1)))

Make1 (list1)


Run the above code, you can see, when change the iteration variable stored in the string value, iteration variables and subscript access list elements memory address is not the same,
Look, can't change the value of the parameter through the iteration variable,
In c #, simply pass the compilation to iteration variable assignment,

CodePudding user response:

reference tsrjrjdy reply: 3/f
Quote: reference 1 floor Vv. Stone3 response:
this code is not on the list to increase deleted, just will list the contents of the traversal string concatenation and printed

Is the feeling which block of code will change list?

For the name in magicians:

The magician='the Great' + name

Name=magician
This won't be in the traverse the list of list elements to change?

First name to traverse the list of magicians, and the second name you are to give him assignment
If you want to change the elements in the list
So to write
 
N=0
For the name in magicians:
The magician='the Great' + name
Magicians [n]=magician
N +=1

CodePudding user response:

Because there is no magicians to return values, to the magicians assignment, or the original value, so,
  • Related