Linux 拨号vps windows公众号手机端

python函数如何设置默认值

lewis 6年前 (2019-03-16) 阅读数 11 #程序编程
文章标签 python

在python中使用def关键词给函数设置默认值,具体方法如下:

def关键词语法:

def 函数名(...,形参名,形参名=默认值):

代码块

使用方法:

defdis_str(str1,str2="http://www.baidu.com/python/"):

print("str1:",str1)

print("str2:",str2)

dis_str("http://www.baidu.com/shell/")

dis_str("http://www.baidu.com/java/","http://www.baidu.com/golang/")

输出结果为:

str1: http://www.baidu.com/shell/

str2: http://www.baidu.com/python/

str1: http://www.baidu.com/java/

str2: http://www.baidu.com/golang/



版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门