In [1]:
print('Hello, world!')


Hello, world!

Heading 1

Heading 2

  • this
  • is
  • a
  • long, long, list
$$ \alpha, \beta, \gamma $$

In [2]:
3


Out[2]:
3

In [3]:
3 * 4 + 5


Out[3]:
17

In [4]:
3 / 5


Out[4]:
0.6

In [5]:
3 // 5


Out[5]:
0

In [6]:
7 % 5


Out[6]:
2

In [7]:
2 ** 3


Out[7]:
8

In [8]:
2 ^ 3


Out[8]:
1

In [9]:
2 << 4


Out[9]:
32

In [10]:
3.14


Out[10]:
3.14

In [11]:
True, False


Out[11]:
(True, False)

In [12]:
1 == 1


Out[12]:
True

In [13]:
1 != 1


Out[13]:
False

In [14]:
None

In [15]:
'hello'


Out[15]:
'hello'

In [16]:
"hello"


Out[16]:
'hello'

In [17]:
"hello's"


Out[17]:
"hello's"

In [18]:
3 + 4j


Out[18]:
(3+4j)

In [19]:
[1,2,3,4]


Out[19]:
[1, 2, 3, 4]

In [20]:
[1,'a', 'hello', 3.14, 4j]


Out[20]:
[1, 'a', 'hello', 3.14, 4j]

In [22]:
print('''This is
a triple
quoted string''')


This is
a triple
quoted string

In [23]:
set([1,1,2,2,3,4,3,4])


Out[23]:
{1, 2, 3, 4}

In [24]:
{'tom': 23, 'anne': 34}


Out[24]:
{'anne': 34, 'tom': 23}

In [25]:
(1,2,3)


Out[25]:
(1, 2, 3)

In [26]:
x = [1,2,3,4]

In [27]:
x


Out[27]:
[1, 2, 3, 4]

In [28]:
x[0]


Out[28]:
1

In [29]:
x[-1]


Out[29]:
4

In [30]:
x[0:2]


Out[30]:
[1, 2]

In [31]:
x[:2]


Out[31]:
[1, 2]

In [32]:
x[1:]


Out[32]:
[2, 3, 4]

In [33]:
x[:]


Out[33]:
[1, 2, 3, 4]

In [34]:
contacts = {'tom': 23, 'anne': 34}

In [36]:
contacts['anne']


Out[36]:
34

In [37]:
contacts.keys()


Out[37]:
dict_keys(['anne', 'tom'])

In [38]:
contacts.values()


Out[38]:
dict_values([34, 23])

In [40]:
names = list(contacts.keys())

In [41]:
names


Out[41]:
['anne', 'tom']

In [42]:
names[0][1:3]


Out[42]:
'nn'

In [43]:
names['bob']



TypeErrorTraceback (most recent call last)
<ipython-input-43-b3004fa8f307> in <module>()
----> 1 names['bob']

TypeError: list indices must be integers or slices, not str

In [44]:
contacts['bob']



KeyErrorTraceback (most recent call last)
<ipython-input-44-9d26b823cea8> in <module>()
----> 1 contacts['bob']

KeyError: 'bob'

In [45]:
1/0



ZeroDivisionErrorTraceback (most recent call last)
<ipython-input-45-05c9758a9c21> in <module>()
----> 1 1/0

ZeroDivisionError: division by zero

In [46]:
squares = []
for i in range(1, 10):
    squares.append(i**2)

In [47]:
squares


Out[47]:
[1, 4, 9, 16, 25, 36, 49, 64, 81]

In [52]:
count = 0
while count < 10:
    print(count)
    if count % 3 == 0:
        break
    count += 1


0

In [54]:
x = 10
if x % 3 == 0:
    print('divisible by 3')
elif x % 5 == 0:
    print('Divisible by 5')
else:
    print('something else')


Divisible by 5

In [57]:
help(range)


Help on class range in module builtins:

class range(object)
 |  range(stop) -> range object
 |  range(start, stop[, step]) -> range object
 |  
 |  Return an object that produces a sequence of integers from start (inclusive)
 |  to stop (exclusive) by step.  range(i, j) produces i, i+1, i+2, ..., j-1.
 |  start defaults to 0, and stop is omitted!  range(4) produces 0, 1, 2, 3.
 |  These are exactly the valid indices for a list of 4 elements.
 |  When step is given, it specifies the increment (or decrement).
 |  
 |  Methods defined here:
 |  
 |  __contains__(self, key, /)
 |      Return key in self.
 |  
 |  __eq__(self, value, /)
 |      Return self==value.
 |  
 |  __ge__(self, value, /)
 |      Return self>=value.
 |  
 |  __getattribute__(self, name, /)
 |      Return getattr(self, name).
 |  
 |  __getitem__(self, key, /)
 |      Return self[key].
 |  
 |  __gt__(self, value, /)
 |      Return self>value.
 |  
 |  __hash__(self, /)
 |      Return hash(self).
 |  
 |  __iter__(self, /)
 |      Implement iter(self).
 |  
 |  __le__(self, value, /)
 |      Return self<=value.
 |  
 |  __len__(self, /)
 |      Return len(self).
 |  
 |  __lt__(self, value, /)
 |      Return self<value.
 |  
 |  __ne__(self, value, /)
 |      Return self!=value.
 |  
 |  __new__(*args, **kwargs) from builtins.type
 |      Create and return a new object.  See help(type) for accurate signature.
 |  
 |  __reduce__(...)
 |      helper for pickle
 |  
 |  __repr__(self, /)
 |      Return repr(self).
 |  
 |  __reversed__(...)
 |      Return a reverse iterator.
 |  
 |  count(...)
 |      rangeobject.count(value) -> integer -- return number of occurrences of value
 |  
 |  index(...)
 |      rangeobject.index(value, [start, [stop]]) -> integer -- return index of value.
 |      Raise ValueError if the value is not present.
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |  
 |  start
 |  
 |  step
 |  
 |  stop


In [ ]: