python - def自定义函数的疑惑
怪我咯
怪我咯 2017-04-18 10:20:28
0
3
751
def change(n):
    n = 'Mr.Gumby'
name = 'Mrs.Entity'
change(name)

这个例子,没太看懂def定义的函数起到了什么作用?
还有一例:

def change(n)
    n[0] = 'Mr.Gumby'
name = ['Mrs.Entity','Mrs.Thing']
change(name)

求解释一下自定义函数起到的作用?
自定义的函数在这个过程中做了什么?怎么做的?

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(3)
洪涛

The method you wrote cannot do anything;
You need to return

Ty80

Custom function is to encapsulate many things to be done into a method that you can call anywhere.

Ty80

You don’t know the function of the above function. In fact, it is largely because the function structure above is too simple and has no return value. You can look at slightly more complex functions to understand the construction and calling methods of the function, and you will understand. It's a function. For example, in your second method above, if you need to modify the m-th element in the name list, write this function as a function, and then attach the list and index variables when calling it. You can modify any list through this function. Elements at any position, imagine that the same operation needs to be performed several times at different locations in the code, and just call this function there.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!