"Stupid way to learn Python" 18th Lesson notes __python

Source: Internet
Author: User
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.

Related Article

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.