# 定义两个必选参数的函数
def my_pow1(x, n):
if not isinstance(x, (int, float)) or not isinstance(n, (int, float)):
raise Exception("Input type error")
result = 1
for i in range(n):
result *= x
return result
print("3**5 = ", my_pow1(3, 5))
# 输出: 3**5 = 243
# print(my_pow1('A3', 5)) # raise error
# 定义一个必选参数和一个默认参数
def my_pow2(x, n=2):
if not isinstance(x,
Python必选参数,默认参数,可选参数,关键字参数实例说明
最新推荐文章于 2023-07-15 09:25:57 发布