Unpacking sequences. : Assign « Tuple « Python Tutorial

Home
Python Tutorial
1.Introduction
2.Data Type
3.Statement
4.Operator
5.String
6.Tuple
7.List
8.Dictionary
9.Collections
10.Function
11.Class
12.File
13.Buildin Function
14.Buildin Module
15.Database
16.Regular Expressions
17.Thread
18.Tkinker
19.wxPython
20.XML
21.Network
22.CGI Web
23.Windows
Python Tutorial » Tuple » Assign 
6.2.7.Unpacking sequences.
create sequences
aString = "abc"
aList = 12]
aTuple = "a""A"1

# unpack sequences to variables
print "Unpacking string..."
first, second, third = aString
print "String values:", first, second, third

print "\nUnpacking list..."
first, second, third = aList
print "List values:", first, second, third

print "\nUnpacking tuple..."
first, second, third = aTuple
print "Tuple values:", first, second, third

# swapping two values
x = 3
y = 4

print "\nBefore swapping: x = %d, y = %d" x, y )
x, y = y, x     # swap variables
print "After swapping: x = %d, y = %d" x, y )
6.2.Assign
6.2.1.How to Create and Assign Tuples
6.2.2.How to Update Tuples
6.2.3.Creation, Repetition, Concatenation
6.2.4.joining their elements together
6.2.5.containing mutable objects that can be changed.
6.2.6.Creating and accessing tuples.
6.2.7.Unpacking sequences.
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.