Tutorialspoint

Compile and Execute C++0x Onlinej

#!/usr/bin/python3

tup = ('physics', 'chemistry', 1997, 2000);

print (tup)
del tup;
print "After deleting tup : "
print tup

Compile and Execute C++0x Onlinej

#!/usr/bin/python3

tup1 = (12, 34.56)
tup2 = ('abc', 'xyz')

# Following action is not valid for tuples
# tup1[0] = 100;

# So let's create a new tuple as follows
tup3 = tup1 + tup2
print (tup3)

Compile and Execute C++0x Onlinej

#!/usr/bin/python3

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])

Compile and Execute C++0x Onlinej

#!/usr/bin/python3

list1 = ['physics', 'Biology', 'chemistry', 'maths']
list1.sort()
print ("list now : ", list1)

Compile and Execute C++0x Onlinej

#!/usr/bin/python3

list1 = ['physics', 'Biology', 'chemistry', 'maths']
list1.reverse()
print ("list now : ", list1)

Compile and Execute C++0x Onlinej

#!/usr/bin/python3

list1 = ['physics', 'Biology', 'chemistry', 'maths']
list1.remove('Biology')
print ("list now : ", list1)
list1.remove('maths')
print ("list now : ", list1)

Compile and Execute C++0x Onlinej

#!/usr/bin/python3

list1 = ['physics', 'Biology', 'chemistry', 'maths']
list1.pop()

print ("list now : ", list1)
list1.pop(1)
print ("list now : ", list1)

Compile and Execute C++0x Onlinej

#!/usr/bin/python3

list1 = ['physics', 'chemistry', 'maths']
list1.insert(1, 'Biology')
print ('Final list : ', list1)

Compile and Execute C++0x Onlinej

#!/usr/bin/python3

list1 = ['physics', 'chemistry', 'maths']
print ('Index of chemistry', list1.index('chemistry'))
print ('Index of C#', list1.index('C#'))

Compile and Execute C++0x Onlinej

#!/usr/bin/python3

list1 = ['physics', 'chemistry', 'maths']
list2 = list(range(5))     #creates list of numbers between 0-4
list1.extend(list2)
print ('Extended List :', list1)

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.