Python Learning (eight)--Variable parameter function

Source: Internet
Author: User

# -*- coding: cp936 -*-  #下面这个函数接受voltage为必选参数, the remaining three are optional parameters Def parrot (voltage,state= ' A stiff ', action= ' voom ', type= ' Norwegian blue '):p rint ("--this parrot wouldn ' t", action,end= '   ') print ("If you put", Voltage, "Volts through it") print ("-- lovely plumage, The ", type) print ("-- it ' s ", State,"! ") #在调用时, in addition to the first required parameter, all parameters must indicate the keyword, the order is not important parrot (223) Parrot (1000,action= ' Kill ') Parrot (10000,state= ' died ') Parrot (10000 , type= ' Chinese parrot ', state= ' lively ') print ("*" *40) #下面这个函数包含字典数据类型def  cheeseshop (kind, * Arguments, **keywords):     print ("-- do you have any",  kind,   "?")     print ("-- i ' M sorry, we ' Re all out of",  kind)      for arg in arguments:        print ( ARG)     print ("-"  * 40)     keYs = sorted (Keywords.keys ())   #对关键字排序     for kw in keys:         print (kw,  ":",  keywords[kw]) #调用该测试函数cheeseshop (' Sweet ', ' It ' s kind of you,sir! ', ' thank you! ', name= ' zzw ', age= ', sex= ' male ')



Python Learning (eight)--Variable parameter function

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.