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
| 1 | cmp(tuple1, tuple2) |
| 2 | len(tuple) |
| 3 | max(tuple) |
| 4 | min(tuple) |
| 5 | tuple(seq) |
python
hah***63.com
>>> tup1 = ("all") >>> print tup1 allall()tuple1
>>> tup1 = ("all",) >>> print tup1 ('all',) >>>python
hah***63.com
destiny
759***[email protected]
destiny
759***[email protected]
635***[email protected]
:
635***[email protected]
284***[email protected]
:
>>> tu = ("alex", [11, 22, {"k1": 'v1', "k2": ["age", "name"], "k3": (11,22,33)}, 44]) >>> tu[1][2]["k2"].append("seven") >>> print(tu[1][2]["k2"]) ['age', 'name', 'seven'] >>>284***[email protected]
115***[email protected]
115***[email protected]
Anofanog
277***[email protected]
>>> T = ('aa','bb','cc','dd','ee') >>> T = T[0:3]+T[4:] >>> print(T) ('aa', 'bb', 'cc', 'ee')Anofanog
277***[email protected]
YsoSeriousSo
331***[email protected]
@Anofanog
T = ('aa','bb','cc','dd','ee')T[4] 'ee', T[4:] ('ee',) T[4]
psT[4:4]
YsoSeriousSo
331***[email protected]
747***[email protected]
747***[email protected]