数:
0.形参和实参:
>>> def saysomething(name, words): \\name是形参; Jenny是实参
print(name + ‘->‘ + words)
>>> saysomething("jenny", "happy")
jenny->heppy
1.关键字函数:
>>> def saysomething(name, words):
print(name + ‘->‘ + words)
>>> saysomething(words = "happy", name = "jenny")
jenny->happy
2. 默认函数:
>>> def saysomething(name = "jenny", words = "happy"):
print(name + ‘->‘ + words)
>>> saysomething()
jenny->happy
>>> def saysomething(name, words):
print(name="jenny" + ‘->‘ + words="happy") \\不能在print里面赋实参
SyntaxError: invalid syntax
3. 收集函数(可变参数):
>>> def test(* paratest):
print("有 %d 个参数" % len(paratest)) \\ 不明白
print("第二个参数是:", paratest[1])
>>> test(‘j‘,‘e‘,‘n‘,‘n‘,‘y‘)
有 5 个参数
第二个参数是: e
原文地址:https://www.cnblogs.com/jiangkeji/p/9084759.html
时间: 2024-10-29 17:20:14