Jypyer notebook Important shortcut keys
Shift + Enter: executes the current cell
Tab: code completion or indent
Shift + Tab: tooltip
Cell Types
Markdown: contains text
Code: contains code
Comments
# one line comment starts with a pound sign
'''
Multi line commnet
Using three 's
'''print 'Hello World'
a = 2
print ("a = " + str(a))Lists
In python a list can hold obejcts of different types
l = [1, 2, '3', 'Hello']
print l
print l[0] #first item in list
print l[1] #second item in list
print l[-1] #last item in list
print l[-2] #second from last l.append('new item')
print lDictionaries
Key, value pairs. Unlike lists, dictionaries do not keep any orders for their items and items are accessible using keys. Keya must be unique but values can be repeated.
dict = {'key1': 1, 'key2': "hello", 'key3': 4}
print dict['key2']#Tuples
Similar to lists but they are immutable. it means that after initializing a tuple its values cannot be changed
t = (1, 2, 3, 4, 1)
len(t) # number of items in t
print ("the frequency of 1 in this tuple is: " + str(t.count(1)))
t[1] # second itemt[1]=2 # error -> tuples are immutable!Sets
Sets are unordered lists of unique elements. Similar to dictionaries with only keys (no values)
l = [1,1,2,2,3,3,3,4,4] # a list
s = set(l) #repetitive values in l will be removed
print s