C + + to python knowledge of one of the little notes

Source: Internet
Author: User

#-*-Coding:utf-8-*-  #utf-8 Support Chinese encoding  words=[' cat ', ' dog ', ' chicken ']for W in words[:]:   #words [:] Copied the original list    Words.insert (0, w) Print Words a = Range (0,10,4) print Aargs=[3,10,3]print range (*args) #[3, 6, 9] #我们还可以把range的argument储存在list或tuple中  def F (A, l=[]):    L.append (a)     return l  Print f (1) print F (2) print F (3) [1][1, 2][1, 2, 3] The default value of the function parameter is initialized only the first time, which is the static variable ' def A (a=0):    a=a+1    Print A a () a () "But this shows only 1 because the Mutable object in Python is List,dictionary,instances" def AA (*args,**keys):    for a in args:        print a    for D in keys:        print D, ' : ', keys[d]      AA (1,2,3,a=1,b=2,c=3) #类似cpp的 *arg Plus * indicates that it will accept arbitrary arg,** to accept arbitrary dict  def Parrot (Voltage, state= ' a stiff ', action= ' voom '):    print "--this parrot wouldn ' t", action,  &NB Sp Print "If you put", voltage, "volts through it.",  &NBSp Print "E ' s", State, "!"   d = {"state": "Bleedin ' demised", "Voltage": "Four Million", "Action": "Voom"}parrot (**d) #--this parrot would N ' t voom if you put the four million volts through it. E ' s bleedin ' demised! #我们可以把参数保存在字典中 if key is corresponding to argument.   f=lambda a,b,c:a*b+cprint F (2,3,5) # Enter the previous argument, return the following value   #字典树user ={}user[' CS ']={}user[2]={}user[' cs ' [' bo ']=1user[' CS ' [' Co ']=2user[2][1]= 1print User.keys () print user.values () print user[' CS '].values () print user[' CS '].keys ()

C + + to python knowledge of one of the little notes

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.