Python

Python

(Python 2.0+)

tup1 = ('physics', 'chemistry', 1997, 2000) tup2 = (1, 2, 3, 4, 5 ) tup3 = "a", "b", "c", "d"

tup1 = ()

tup1 = (50,)

0


:

(Python 2.0+)

#!/usr/bin/python tup1 = ('physics', 'chemistry', 1997, 2000) tup2 = (1, 2, 3, 4, 5, 6, 7 ) print "tup1[0]: ", tup1[0] print "tup2[1:5]: ", tup2[1:5]

tup1[0]:  physics
tup2[1:5]:  (2, 3, 4, 5)

:

(Python 2.0+)

#!/usr/bin/python # -*- coding: UTF-8 -*- tup1 = (12, 34.56) tup2 = ('abc', 'xyz') # # tup1[0] = 100 # tup3 = tup1 + tup2 print tup3

(12, 34.56, 'abc', 'xyz')

del:

(Python 2.0+)

#!/usr/bin/python tup = ('physics', 'chemistry', 1997, 2000) print tup del tup print "After deleting tup : " print tup

('physics', 'chemistry', 1997, 2000)
After deleting tup :
Traceback (most recent call last):
  File "test.py", line 9, in <module>
    print tup
NameError: name 'tup' is not defined

+ *

Python
len((1, 2, 3))3
(1, 2, 3) + (4, 5, 6)(1, 2, 3, 4, 5, 6)
('Hi!',) * 4('Hi!', 'Hi!', 'Hi!', 'Hi!')
3 in (1, 2, 3)True
for x in (1, 2, 3): print x,1 2 3

L = ('spam', 'Spam', 'SPAM!')
Python
L[2]'SPAM!'
L[-2]'Spam'
L[1:]('Spam', 'SPAM!')

(Python 2.0+)

#!/usr/bin/python print 'abc', -4.24e93, 18+6.6j, 'xyz' x, y = 1, 2 print "Value of x , y : ", x,y

abc -4.24e+93 (18+6.6j) xyz
Value of x , y : 1 2

Python

1cmp(tuple1, tuple2)
2len(tuple)
3max(tuple)
4min(tuple)
5tuple(seq)