1. 程式人生 > >函式引數 Python

函式引數 Python

def my_fun(key1,key2=122):
    print(key1,end=" + ")
    print(key2,end=" = ")
    print(key1+key2)
    
my_fun(100)
my_fun(200,32)

def my_func(key1,key2,*keyy,**keyyy):
    print("key1 =",key1,"  key2 =",key2)
    print("*key  ",keyy)
    print("**keyy  ",keyyy)

my_func(20,38,*('cks','wx',304),**{'q':30,'xkd':393})
my_func(20,38,'cks','wx',304,q=30,xkd=393)

def my_sort(li,desc=None):
    for ii in range(len(li)):
        for j in range(len(li)-1,ii,-1):
            if not desc:    
                if li[j]<li[j-1]:
                    li[j],li[j-1]=li[j-1],li[j]
            else:
                (li[j],li[j-1])=desc(li[j],li[j-1])
     

def desc(x,y):
    if x<y:
        return x,y
    else:
        return y,x

li=[3,5,2,6,30,54,5,34]
my_sort(li)
print(li)
my_sort(li,desc)
print(li)