[Python Crash Course] Basics_Function

# list作参数 #
list_1 = ['a', 'b']


def function_1(list_2):
    print(list_2)
    pass


function_1(list_1[:])   # [:]传递副本,函数操作不会改变原list


# Arbitrary Number of Arguments -> list #
def function_2(*name):
    print(name)


print("Arbitrary Number of Arguments -> list:")
function_2('hello', 'world')


# Arbitrary Number of Arguments -> dictionary #
def function_3(**name):
    print(name)
    # for key, value in name:
    #     name[key] = value


print("Arbitrary Number of Arguments -> dictionary:")
function_3(first='hello', last='world')


# If too many Parameters #
def function_4(
        parameter_1, parameter_2,       # double Tab
        parameter_3, parameter_4):
    pass

 

 

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页