首页 > 编程语言 > 详细

[Python] How to pack and unpack variables in Python?

时间:2014-02-19 14:42:50      阅读:398      评论:0      收藏:0      [点我收藏+]

The follow code snippets show how to use variables smartly.

class MyClass():
    def pack(self,**kwargs):
        for key in kwargs:
            print key +"=>"+ kwargs[key];
    def unpack(self,a,b):
        print a
        print b

if __name__ == ‘__main__‘:
    my = MyClass()
    my.pack(name="developer",skill="java")
    p = (1,2)
    p = [3,4]
    my.unpack(*p)
    p = {‘a‘:5,‘b‘:6}
    my.unpack(**p)


[Python] How to pack and unpack variables in Python?

原文:http://blog.csdn.net/wonderfan/article/details/19415473

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!