the 18th lesson of the stupid way to learn Python
This class will create a function that is similar to the definition function in the C language.
The author adds an English comment that explains the function at the beginning of each function. For ease of understanding, I will directly explain some of the code involved in the knowledge point after the original code. The definition function is what the author says about creating a function.
The original code that has been partially modified is as follows:
# This one's like your scripts with argv the first function created is similar to the argv
def print_two (*args) in the previous section: * is not the meaning of the pointer, like all the meanings in the SQL language. Args is a list variable with more than one value.
arg1, arg2 = args
print "arg1:%r, arg2:%r"% (arg1, arg2)
# OK, that *args is actually pointless, we can Ju St do this means argv meaningless, you can skip direct operation
def print_two_again (ARG1,ARG2): The variables in parentheses are separated by commas from
print "arg1:%r, arg2:%r"% ( ARG1,ARG2)
# This just takes one argument can also define a function
def print_one (Arg1) with a single parameter:
print "arg1:%r"% arg1
# This one takes no Argumengts can also define a function
def print_none () with no parameters: in fact, the definition function does not necessarily have to be underlined. But it can't start with numbers, it's made up of digital letters, like C.
print "I got Nothin '."
Print_two ("Steve", "Wang")
Print_two_again ("Steve", "Wang")
Print_one ("first!"
) Print_none ()
The results are as follows:
What is involved in this lesson
Please according to the author said, intentionally wrong code, check error message, I anyway coherent, haha [doge].
It is very simple to add a point exercise, please try to understand every problem.