Python Learning Notes (vii) function

Source: Internet
Author: User

Original link: http://www.cnblogs.com/vamei/archive/2012/06/01/2529500.html#!comments

Function learning has encountered a problem

1 #!/usr/bin/env python2 #Coding=utf-83 #Start learning functions today4 defSquare_sum (A, b):5c = a**2 + b**26     returnC7 #actually learn python come over, have been not very good programming thinking, thinking will always be limited by the original Yi script8 #expect a breakthrough.9 Ten #def define defines the function, Square_sum is the function name, does not explicitly restrict oneself to remember to live on the line, preferably by the function name record One #returns can return multiple values ASquare_sum (9, 6) -     return(A, B, c) -  the #The 12th line of Square_sum (9, 6) thinks so, can return the value directly, turns out to be wrong -     Print(Square_sum (9, 6))#nor did it execute

It's strange to have no execution, and then go to the online Python editor, and there is no output

1 #!/usr/bin/env python2 #Coding=utf-83 #Start learning functions today4 defSquare_sum (A, b):5c = a**2 + b**26     returnC7 #actually learn python come over, have been not very good programming thinking, thinking will always be limited by the original Yi script8 #expect a breakthrough.9 Ten #def define defines the function, Square_sum is the function name, does not explicitly restrict oneself to remember to live on the line, preferably by the function name record One #returns can return multiple values ASquare_sum (9, 6) - #return (A, B, c) -  the #The 12th line of Square_sum (9, 6) thinks so, can return the value directly, turns out to be wrong - Print(Square_sum (9, 6))#nor did it execute

You can return the value of the sum of squares after you modify it.

#上面应该是print is inside the function definition, so do not execute? The words of the great God wish to be answered

And finally put the full note on it.

1 #!/usr/bin/env python2 #Coding=utf-83 #Start learning functions today4 defSquare_sum (A, b):5c = a**2 + b**26     returnC7 #actually learn python come over, have been not very good programming thinking, thinking will always be limited by the original Yi script8 #expect a breakthrough.9 Ten #def define defines the function, Square_sum is the function name, does not explicitly restrict oneself to remember to live on the line, preferably by the function name record One #Return returns multiple values, and return is not required ASquare_sum (9, 6) - #return (A, B, c) -  the #the 10th line of Square_sum (9, 6) thinks so, can return the value directly - Print(Square_sum (9, 6))#nor did it execute - #inside the shell, Square_sum (9, 6) can return values directly, and print (Square_sum (9,6)) can also perform - #why not? has been resolved +  -  +A = 1 A  at defChange_integer (a):#integer Shaping -A = a + 1 -     returna -  - Print(Change_integer (a)) - Print(a) in #Output Result: - #Print (Change_integer (a)) 2 to #Print (a) 1 + #Use the word of the author, and you may not be able to say it clearly . - #An integer variable is passed to the function, the function operates on him, but the original integer variable A does not change the #A = 1 is to create a variable A in memory, and then assign 1 to A; Basic data type variable, the variable is passed to the function, the function will assign a new variable in memory, and then complete the new assignment, will not affect the original variable, called value passing *  $b = [1, 2, 3]Panax Notoginseng  - defChange_list (b): theB[0] = b[0] + 1 +     returnb A  the Print(Change_list (b)) + Print(b) - #Output Result: $ #Print (change_list (b)) [2, 2, 3] $ #print (b) [2, 2, 3] - #for a table, the table is passed to the function is a pointer, the pointer to the sequence in the position, [0], in the function of the table operation is in the original memory, so the list changes, called pointer passing -  the #The author left homework, judging leap years, I think I can't write this slag

Python Learning Notes (vii) function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.