在应用Python多年今后,我有时发清楚明了一些我们页堪不知道的功能和特点。一些可以说是异常有效,但却没有充分应用。推敲到这一点,我编辑了一些你应当懂得的Python功能特点。
带随便率性数量参数的函数
你可能已经知道了Python许可你定义可选参数。但还有一个办法,可以定义函数随便率性数量的参数。
起首,看下面是一个只定义可选参数的例子
- def function(arg1="",arg2=""):
- print "arg1: {0}".format(arg1)
- print "arg2: {0}".format(arg2)
- function("Hello", "World")
- # prints args1: Hello
- # prints args2: World
- function()
- # prints args1:
- # prints args2:
- def foo(*args): # just use "*" to collect all remaining arguments into a tuple
- numargs = len(args)
- print "Number of arguments: {0}".format(numargs)
- for i, x in enumerate(args):
- print "Argument {0} is: {1}".format(i,x)
- foo()
- # Number of arguments: 0
- foo("hello")
- # Number of arguments: 1
- # Argument 0 is: hello
- foo("hello","World","Again")
- # Number of arguments: 3
- # Argument 0 is: hello
- # Argument 1 is: World
- # Argument 2 is: Again
使用Glob()查找文件
推荐阅读
媒介<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"> 简单工作简单做-宽度自适应所谓宽度自适应严格来说是一种PC端的自适>>>详细阅读 地址:http://www.17bianji.com/lsqh/35585.html 1/2 1

网友点评
精彩导读
科技快报
品牌展示