函数参数
默认参数
关键字参数
VarArgs参数
Code
# -*- coding: utf-8 -*-
# default parameter
def repeated_str(str,times = 1):
repeated_strs = str * times
return repeated_strs
# repeated_strings = repeated_str("hello world")
# print(repeated_strings)
repeated_strings = repeated_str("hello world\n",4)
print(repeated_strings)
# keyword parameter
def func(a,b = 4,c = 8):
print("a is ",a,"b is ",b,"c is ",c)
func(13,17)
func(100,c = 101)
func(c = 200,a = 10)
# varArgs parameter
def print_paras(fpara,*nums,**words):
print("fpara= "+str(fpara))
print("nums= "+str(nums))
print("words= "+str(words))
print_paras("hello world",1,2,3,4,a = 10,b = 20,c = 30)
console
hello world
hello world
hello world
hello world
a is 13 b is 17 c is 8
a is 100 b is 4 c is 101
a is 10 b is 4 c is 200
fpara= hello world
nums= (1, 2, 3, 4)
words= {'c': 30, 'a': 10, 'b': 20}