Python Road "third": Python Basics (14)--Function default parameters

Source: Internet
Author: User

# default parameter: Must be placed at the end of the formal parameter list


# def send (name,xx = "OK"):
# ...
# # using default parameters
# Send ("Eric") #对形式参数的第一个元素赋值, the second element uses the default parameters.
# # Specify Parameters
# Send ("Eric", "No") #对形式参数的第一个元素赋值, the default parameter of the second element is re-assigned.
#

# def send (mail_addr,xx = "OK", content,): #xx = "OK" in the middle will be an error
def send (mail_addr,content,xx ="OK"):#默认参数需要放到参数列表最后, xx = "OK" is re-assigned when the function is called.
Print (MAIL_ADDR,CONTENT,XX)
# print ("Send mail success:", Mail_addr,content)
Return True

While True:
EM =Input"Please enter your email address:")
# result = Send (EM) #TypeError: Send () Missing 1 required positional argument: ' Content '
#报错, the actual parameter is passed 1, the formal parameter is 2.
result = Send (em,"Good luck","no") #em是参数传递的内容, can be multiple, default is one by one corresponding
#
if result = = True:
Print ("Send Success")
Else:
Print ("Send Failed")

Python Road "third": Python Basics (14)--Function default parameters

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.