|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
测试题:
0.
x:形参
y:实参
1.
直接用'#',只有在代码文件里被看见,而用函数文档'str',则可以用:函数名.__doc__或者help(函数名)查看.
2.
可以避免参数过多导致的参数赋值错乱,导致函数出来不是自己想要的样子.
3.
step = ' ' 参数间间隔为一个空格,end = '\n 默认打印完换行, file = sys.stdout 母鸡,flush = False 母鸡
4.
1)调用函数时,默认函数可以不再赋值,关键字参数必须赋值
动动手:
0.
def x(*L):
total = 0
if L[len(L) - 1] == 5:
base = 5
for i in L:
total += i
total -= 5
else:
base = 3
for i in L:
total += i
total *= base
return total
1.
def sxh():
num = list(range(100,1000))
for temp in num:
n = temp
L = list()
while temp:
L.insert(0,(temp % 10))
temp //= 10
total = 0
for l in L:
total += l**3
if n == total:
print(n)
2.
def findstr():
line = input('请输入目标字符串:')
char2 = input('请输入子字符串(两个字符):')
total = 0
for each in range(len(line)-1):
if line[each] == char2[0] and line[each + 1] == char2[1]:
total += 1
print('子字符串在目标字符串中共出现',total,'次')
课堂笔记:
1. 函数参数有形式参数和实际参数,如fix(x),x=2,x是形参,传进去的2是实参
2. 函数有关键字参数和默认参数,如fix(a,b),fix(b=2,a=1),有了关键字参数,就能降低参数过多时,参数数据传输错误的情况;而fix(a = 1,b = 2),叫做默认参数,在有默认参数的情况下,如果调用函数的时候不传参数,就会使用默认参数.
3. 搜集参数:fix(*n),当不确定传多少参数时使用搜集参数,当参数中不止搜集参数时,其他参数赋值的时候需要用关键字参数,或者干脆使用默认参数. |
|