Thursday, 21 November 2019

40 #INDEXING, #LISTS

#INDEXING
#Requesting data from lists!!!

#Lists01 Calling one specific value
print ('#Lists01')
L01 = ["cat", "bat", "rat", "elephant"]
print (L01 [1])

print()

#Lists02 Calling specific values in 2 lists
print ('#Lists02')
L02 = [['cat', 'bat'], [10, 20, 30, 40, 50]]
print (L02[0])
print (L02[0][1])
print (L02[1][4])

print ()

#Lists03 Calling out a specific value counting from the back
print ('#Lists03')
L03 = ['cat', 'bat', 'rat', 'elephant']
print (L03[-1])
print (L03[-3])
print ('The ' + L03[-1] + ' is afraid of the ' + L03[-3] + '.')

print()

#Lists04 Calling out a series of values
print ('#Lists04')
L04 = ['cat', 'bat', 'rat', 'elephant']
print (L04[0:4])
print (L04[1:3])
print (L04[0:-1])
print (L04[:2])
print (L04[1:])
print (L04[:])
print (len(L04))

print ()

#Lists05 Changing the values within the list
print ('#Lists05')
L05 = ['cat', 'bat', 'rat', 'elephant']
print (L05)
L05[1]= 'ant'
print (L05)
L05[-1]= 'dog'
print (L05)

print ()

#List06 Replication and concatenation
print ('#Lists06')
L06 = [1, 2, 3] + ['A', 'B', 'C']
print (L06)
print ((L06)*3)

print ()


#List07 Removing values with del
print ('#Lists07')
L07 = ['cat', 'bat', 'rat', 'elephant']
print (L07)
del L07[2]
print (L07)
del L07[2]
print (L07)