python之娱乐类:魔法传值
还记得是一个月的事情,神奇般的在youtube上搜索python,有个老外的教程里面有这么个内容:
#=============================
## python 魔法传值
#=============================
#-*-coding:utf-8-*-
class sono:
def Dict(self,**args):
return args
def Tuple(self,*args):
return args
if __name__ == "__main__":
inst = sono()
dic = inst.Dict(a=1,b=2)
tple = inst.Tuple(1,2)
print dic,tple
有趣的传值(**args) 可以返回字典 就是对输入的数据比较严格 需要 A:X 形式
相关文档:
#快速排序
def Partition(mylist, low, high):
tmp = mylist[low]
while low < high:
while low < high and mylist[high] >= tmp:
high = high - 1
if low < high:
mylist[low] = mylist[high]
low = low + 1
while low < hi ......
# coding=gb2312
# 用中文注释前务必加上第一行
# 求模运算符,和C语言一样
print 10%9
# 整数相除仍然是整数
print 5/2
# 2后加上.就变成浮点数了
print 5/2.
# **表示求幂运算
print 7**4
# 函数用时要加上module.function
import math
print math.floor(19.8)
# 函数名也可以成为变量
func = math.floor
......
Python最大的特点就在于她的快速开发功能。作为一种胶水型语言,python几乎可以渗透在我们编程过程中的各个领域。这里我简单介绍一下用python进行gui开发的一些选择。
1.Tkinter
Tkinter似乎是与tcl语言同时发展起来的一种界面库。tkinter是python的配备的标准gui库,也是opensource的产物。Tkinter可用于win ......
1. Building an Application with PyGTK and Glade
2. Creating a GUI using PyGTK and Glade
3. A Beginner's Guide to Using pyGTK and Glade
4. Is there a walkthrough on getting PyGTK2 and libglade2 to work on win32 ......
过量的参数
在运行时知道一个函数有什么参数,通常是不可能的。另一个情况是一个函数能操作很多对象。更有甚者,调用自身的函数变成一种api提供给可用的应用。
对于这些情况,python提供了两种特别的方法来定义函数的参数,允许函数接受过量的参数,不用显式声明参数。这些“额外”的参数下一步再解释。
注意a ......