Google Python Class Day 1 Part 2

Fonte: Youtube



In [2]:
range(20)


Out[2]:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]

In [3]:
range(0,20)


Out[3]:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]

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


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

In [5]:
a = range(20)

In [6]:
a


Out[6]:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]

In [7]:
print(a)


[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]

In [12]:
a = (1,2,3)
len(a)


Out[12]:
3

In [13]:
a[0]


Out[13]:
1

In [16]:
a = [(1,"b"),(2,"a"),(1,'a')]

In [17]:
sorted(a)


Out[17]:
[(1, 'a'), (1, 'b'), (2, 'a')]

In [19]:
# Tuplas sao imutaveis, veja a original nao foi alterado
a


Out[19]:
[(1, 'b'), (2, 'a'), (1, 'a')]