Python‎ > ‎

tuple

http://www.adilwaseem.com/

Definition
If the argument is a tuple, the return value is the same object.

Syntax
tuple() -> empty tuple
tuple(iterable) -> tuple initialized from iterable's items

Parameters
iterable=number or string

Examples
Assignment 
The tuple value are assigned in to variable.
 >>> 
>>> (x,y,z)=("python", "Lake", "Learning")
>>> print(x)
python
>>> print(y)
Lake
>>> print(z)
Learning

operator.is_(tuple1, tuple2)
The return is tuple is:
 >>> x=('Centre', 'Python', 'Research')
>>> y=('Centre', 'Python', 'Research')
>>> operator.is_(x,y)
False
>>> x is y
False

tuple()
The method map the tuple values using lambda and for statement.
x=(1,2,3)
y=(2,1,3)
z=(1,3,4)
for i in map(lambda a,b,c: a+b+c, x,y,z):
    print(i)
>>> 
4
6
10
>>> 

min(tuple)
Return with the minimum value in the tuple.
tuple1=(44,22,13,22,45,555,32,33)
y=min(tuple1)
print("Minimum item in tuple1 is: ", y)
>>> 
Minimum item in tuple1 is: 13
>>>

max(tuple)
Return with the maximum value in the tuple.
 tuple1=(44,22,13,22,45,555,32,33)
y=max(tuple1)
print("Maxmimum items in tuple1 is: ", y)
>>> 
Maxmimum items in tuple1 is: 555
>>>

len(tuple)
Return with the length of the tuple.
 tuple1=(44,22,13,22,45,555,32,33)
y=len(tuple1)
print(" number of items in tuple1 are: ", y)

operator.length_hint(tuple)
The method return with length of string tuple.
 >>>import operator
>>> x=("Python", "Research", "Centre")
3
>>> len(x)
3

print(tuple)
Return with:
 tuple1=(44,22,13,22,45,555,32,33)
print(tuple1)
>>> 
(44, 22, 13, 22, 45, 555, 32, 33)
>>>

tuple(str))
 >>> x="Python Lake"
>>> tuple(x)
('P', 'y', 't', 'h', 'o', 'n', ' ', 'L', 'a', 'k', 'e')
>>>

Tuple*n
Multiply the tuple by number.
 >>> tuple1=(2,4,6,8,10)
>>> tuple1*3
(2, 4, 6, 8, 10, 2, 4, 6, 8, 10, 2, 4, 6, 8, 10)
>>> 

str.rpartition==tuple
The returns are following:
 >>> "Python Lake".rpartition("h")
('Pyt', 'h', 'on Lake')
>>> type("Python Lake".rpartition("h"))
<class 'tuple'>
>>> z="Python Lake".rpartition("h")
>>> z=('Pyt', 'h', 'on Lake')
>>> z=('Pyt', 'h', 'on Lake')
>>> z.index('h')
1
>>> 'Pyt'+'h'+ 'on Lake'
'Python Lake'
>>> z.count("Lake")
0
>>> z.count('h')
1


str.join(tuple)
Returns are following:
 >>> list=["Python", "Research", "Centre"]
>>> "Lake".join(list)
'PythonLakeResearchLakeCentre'
>>> set={"Pyhton", "Research", "Centre"}
>>> "Lake".join(set)
'ResearchLakePyhtonLakeCentre'
>>> tuple=("Pyhton", "Research", "Centre")
>>> "Lake".join(tuple)
'PyhtonLakeResearchLakeCentre'
>>> list==set
False
>>> set==tuple
False
>>> False==False
True
>>> "Lake".join(tuple)=="Lake".join(set)
False
>>> 'PyhtonLakeResearchLakeCentre'=='ResearchLakePyhtonLakeCentre'
False
>>> 'PythonLakeResearchLakeCentre'=='PythonLakeResearchLakeCentre'
True
>>>


map.__eq__()
The method return with the equality test whether tuple items max() of the map() is equal to pow(23, 3).
x=(11,23,444,333)
y=max(map(lambda a: a, x)).__eq__(pow(22,3))
print(y)
>>> 
False
>>>


The determined that the maximum value of set is not equal to round(.99).
import math
tuple=(math.acos(1),math.asin(.22),math.cos(-1.1), math.atan(.99))
y=max(map(lambda a: a, tuple)).__ne__(round(1.1))
print(y)
>>> 
False
>>>

random.choice(tuple)
The method selected the item from tuple.
import random
tuple=(1,3,5,7,4,6,7)
x=random.choice(tuple)
if x.__lt__(4):
                  print("Random value is more than 4")
else:
      print("Random value is: ",x)

>>> 
Random value is: 6
>>>


tuple(math value)
Return with maximum and minimum degrees values:
import math
import operator

a=math.degrees(33)
b=math.degrees(22)
c=math.degrees(34)
d=math.degrees(13.1)
e=math.degrees(120)

tuple=(a,b,c,d,e)

g=min(tuple)
h=max(tuple)

if operator.truth(abs(g-h)>90):
    print("Minimum degrees value is: ", g)
    print("Maximum degrees value is: ", h)
    print("The difference between minimum and maximum degrees is less 90 Degrees which is: ", abs(g-h))
else:
    print("The difference between minimum and maximum degrees is less 90 Degree which is: ", abs(g-h))

>>> 
Minimum degrees value is:  750.5747116213784
Maximum degrees value is:  6875.493541569878
The difference between minimum and maximum degrees is less 90 Degree which is:  6124.9188299484995
>>> 

itertools(tuple)
The return is equal to:
import itertools
tuple=(3, 4, 1, 2)
z=itertools.islice(tuple,3)
for value in z: print(value)

>>> 
3
4
1
>>>

Comments