Thursday, October 12, 2017

Tuple in Python


Tuple: like as container or array

Sample:
Tuple:
tup1 = ('Sangeeth', 'chennai','1309','gowtham',1990', '2000','0406');
tup2 = (1,2,3,4,5,6,7,8);
print  tup1[1]
print  tup2[3:5]

output:
chennai
3,4,5

String:
var1 = "sangeeth"
var2 = "gowtham"
print var1[0]

print var2[0:3]

output:
s
gow


Packing and Unpacking

Sample:

x = ("Sangeeth", chennai, "madurai")    # Tuple packing code
(me, where, too) = x    # Tuple unpacking Code
print me
print where
print to

Output
Sangeeth
chennai
madurai

Comparison Operator
A comparison operator in Python can work with tuples.It starts with comparing the first element from each of the tuples

Sample:
a=(3,8)
b=(2,4)
if (a>b):print "a is bigger"
else: print "b is bigger"
    
a=(4,7)
b=(4,3)
if (a>b):print "a is bigger"
else: print "b is bigger"
    
a=(2,3)
b=(4,1)
if (a>b):print "a is bigger"
else: print "b is bigger"

Built In Function
all(), any(), enumerate(), max(), min(), sorted(), len(), tuple(), etc.


No comments:

Post a Comment

Convert Call stack to readable format in D365FO X++

//Input --container _xppCallStack = xSession::xppCallStack();  Public static str POL_formatXppCallStack(container _xppCallStack, int _skipFr...