本文共 817 字,大约阅读时间需要 2 分钟。
#!/usr/bin/python
# -*- coding=utf-8 -*- from __future__ import divisiondef count(x,y,operate):
result = {"+":x+y, "-":x-y, "*":x*y, "/":x/y} return result.get(operate)print count(2,3,"*")
#把列表作为参数传递及缺省参数实例
def useargs(args=[],operator="+"):
x = args[0] y = args[1] result1 = {"+":x+y} return result1.get(operator)print useargs((2,3))
def usechundi(**d):
a = d.keys() b = d.values() print a print busechundi(one="1",two="2",three="3")
#字符串的连接 def BuildSqlConnection(sql): return ";".join(["%s=%s" %(k,v) for k,v in sql.items()])sql = {"server":"mpilgrim",
"database":"master", "uid":"sa", "pwd":"secret"}print BuildSqlConnection(sql)
运行结果:
6
5 ['three', 'two', 'one'] ['3', '2', '1'] pwd=secret;database=master;uid=sa;server=mpilgrim
本文转sinojelly51CTO博客,原文链接:http://blog.51cto.com/pnig0s1992/364014,如需转载请自行联系原作者