AI Commands
AI Commands
>>>print(5+5)
>>> listname.append() //to add another item at the end of the list
>>> listname.insert(index,item) //to add item at indexed position and move other items to right
>>> ‘return’ is used to return value from function and break the code as well no statement following
return will be executed
>>> .get() //is used to extract stored data and also can provide default value in case searched word not
found
Code:
friends = ["Ali", "Qasim", "Muhammad"]
2D Lists:
number_grid = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
[0]
]
print(number_grid[0][0)
Translator:
return translation
Lists:
Line = line.rstrip() to eliminate white spaces
If line.startswith(‘From’)
In lists we use indexing but in dictionaries we use ‘KEY’ and a ‘VALUE’, Dictionaries don’t follow order
they are a bag of values with labels.
Dictionaries:
.get to be used for Dictionaries to avoid traceback.
dictionary.get(key,O) // 0 is default value
Tuples:
Tuples are immutable..
Very interested thing about tuples is that can be assigned multiple variables at one time
(x,y) = (8,9)
X=8
Y=9
For comparison tuples only compares till first true and the rest will not be compared.
Di = sorted(di)
NUMPY
Arrays
Np.ones((10,10))
Exercie: