In [ ]:
2 + 2

In [ ]:
2 - 2

In [ ]:
2 - 3

In [ ]:
2 * 4

In [ ]:
2 / 3

In [ ]:
2.0 / 3.0

In [ ]:
2 % 3 # modulus

In [ ]:
5 % 2

In [ ]:
1.0 + 3 # Floating Point

PEMDAS!


In [ ]:
1.0 + 3 * 5.0

In [ ]:
(1.0 + 3) * 5

In [ ]:
(1.0 + 3) * 5. # who needs a zero?

In [ ]:
'single quoted string'

In [ ]:
"double quoted string"

In [ ]:
r'raw \ string' # for regexes and such

In [ ]:
u'unicode ☃ string'

In [ ]:
"""docstring"""

In [ ]:
'string' + 3

In [ ]:
'string' + str(3)

In [ ]:
'string' * 3

In [ ]:
'string' / 3

In [ ]:
'string' * 0

In [ ]:
'string' * -1

In [ ]:
s = 'string'

In [ ]:
s()

In [ ]:
s * 3

In [ ]:
s[0]

In [ ]:
s[-1]

In [ ]:
s[::-1]

In [ ]:
s[2:5]

In [ ]:
s.upper()

In [ ]:
shout = str.upper
shout(s)

In [ ]:
len(s)

In [ ]:
t = (1, 2, 3, 4)

In [ ]:
t

In [ ]:
t[0]

In [ ]:
t[:-1]

In [ ]:
t + t

In [ ]:
t + t ^ 2

In [ ]:
t ^ 2

In [ ]:
t[-1] = 5 # Assignment

In [ ]:
t = t[:-1][5]

In [ ]:
t = t[:-1] + (5, )
print t

Lists

Lists can store all kinds of stuff, and you can iterate over them!!


In [ ]:
len()

In [ ]:
help(len)

In [ ]:
len('string')

In [ ]:
type(5)

In [ ]:
l = [2, 3, 4, 5]

In [ ]:
l.append('string')

In [ ]:
print l

In [ ]:
l[2]

In [ ]:
l[22]

Sets


In [ ]:
j = set([2, 3, 4])

In [ ]:
j.add(5)
j.add(4)

In [ ]:
j

In [ ]:
d = dict()

In [ ]:
# Name and address
d['Remy'] = '123 FOSS St.'

In [ ]:
d['Remy']

In [ ]:
D = dict(keyword=3, k2='go')

In [ ]:
D.values()

In [ ]:
D.keys()

In [ ]:
d.viewkeys()

In [ ]:
D.pop()

In [ ]:
D.pop('k2')

In [ ]:
d.viewkeys()