我是靠谱客的博主 缥缈皮皮虾,这篇文章主要介绍Python必选参数,默认参数,可选参数,关键字参数实例说明,现在分享给大家,希望可以做个参考。

# 定义两个必选参数的函数
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必选参数,默认参数,可选参数,关键字参数实例说明的全部内容,更多相关Python必选参数内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(107)

评论列表共有 0 条评论

立即
投稿
返回
顶部