Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Execute Python-3 Online

mylist=['My','name','is','Nitin','Srivastava']
mylist1=[12,2,19,80]

mylist.sort()
print(mylist)

mylist1.sort()
print(mylist1)

#Converting a list into a tuple

mytuple=(mylist[0:2])
print(mytuple)

mytuple1 =('This','is','another','tuple')

# Note the difference a comma makes
anothertuple=(3)
anothertuple1=(3,)
print(anothertuple*3)
print(anothertuple1*3)

#ADDITION in two lists

mylist2=[9,10,11]
mylist3=[11,12,13]
mylist4=mylist2+mylist3
print(mylist4)
mylist5=[]
for elm in mylist2:
    x= mylist2.index(elm)
    mylist5.append(mylist2[x]+mylist3[x])
print(mylist5)

#List Methods
mylist6=['My','name','is','Nitin','Srivastava']
mylisttemp="Nitin"
mylist6.extend(mylisttemp)
print(mylist6)
mylist6.append(mylisttemp)
print(mylist6)

print(mylist6[2:9])
print(mylist6[2:9:2])

#Zipping
a=['One','Two','Three']
b=[1,2,3]
c=zip(a,b)
print(c)

callers=[] 
for c in range(11):
  callers.append(c)
  
while callers:
  print(callers.pop(0))
  
 #Tuples packaging
q=('o','n','e')
r=('t','w','o')
s=q+r
print(s)

#Unpackaging
n,i,t,s,r,v=s
print(n,i,t,s,r,i)

joinedtuple=('one','two','three')
x,y,z=joinedtuple
print(x,y,z)
 

Advertisements
Loading...

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