码迷,mamicode.com
首页 > 编程语言 > 详细

python之打包,解包

时间:2016-06-30 21:22:52      阅读:154      评论: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)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!