Python函数的默认参数和返回值的简单示例

#-*- coding:utf-8-*-
import sys
def arithmetic(x=1,y=1,operator="-"):
	result={
		"+":x+y,
		"-":x-y,
		"*":x*y,
		"/":x/y,
	}
	return result.get(operator)
if __name__=="__main__":
	print arithmetic(3)
	print arithmetic(4,3)
	print arithmetic(4,5,"*")

你可能感兴趣的:(Python)