首页 > 编程语言 > 详细

python之打包,解包

时间:2016-06-30 21:20:17      阅读:240      评论:0      收藏:0      [点我收藏+]
#coding:utf-8
#字符串,列表,元组打包与解包
aString = abc
aList = [1, 2, 3]
aTuple = a, A, 1

print(Unpacking string......)
first, second, third = aString
print("string values:", first, second, third)

print(\nUnpacking list......)
first, second, third = aList
print("string values:", first, second, third)

print(\nUnpacking tuple......)
first, second, third = aTuple
print("string values:", first, second, third)

#swapping two values
x = 3
y = 4
print(\nBefore swapping: x = %d,y =%d % (x, y))
#首先将右边的部分打包成一个元组,即(4,3),而后解包指派给变量x,y
x, y = y, x #swap Variables
print(After swapping: x = %d, y = %d % (x, y))

 

python之打包,解包

原文:http://www.cnblogs.com/changbo/p/5631084.html

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