Tipos Básicos (list, tuple)
In [1]:
numero = 10
In [4]:
type(numero)
Out[4]:
In [3]:
numero = 10.0
In [5]:
valor = False
In [6]:
type(valor)
Out[6]:
In [7]:
frutas = ["laranja", "banana", "tomate"]
In [9]:
frutas[0]
Out[9]:
In [10]:
frutas[-1]
Out[10]:
In [11]:
type(frutas)
Out[11]:
In [12]:
frutas.append("maça")
In [13]:
frutas
Out[13]:
In [14]:
dir(frutas)
Out[14]:
In [15]:
frutas[0]
Out[15]:
In [16]:
frutas.__getitem__(0)
Out[16]:
In [17]:
frutas + ["pêra"]
Out[17]:
In [18]:
str(frutas)
Out[18]:
In [19]:
len(frutas)
Out[19]:
In [20]:
frutas[:2]
Out[20]:
In [21]:
frutas = frutas + ["pêra"]
In [22]:
frutas[:1]
Out[22]:
In [23]:
frutas[1:3]
Out[23]:
In [24]:
frutas[0:5:2]
Out[24]:
In [25]:
numeros = (0, 1, 2, 3, 4, 5)
In [26]:
numeros[0]
Out[26]:
In [27]:
frutas[0] = "uva"
print(frutas)
In [28]:
numeros[0] = -1
In [29]:
frutas[::-1]
Out[29]:
In [30]:
info = {"nome": "gileno", "email": "contato@gilenofilho.com.br"}
In [31]:
info["nome"]
Out[31]:
In [32]:
for item in frutas:
print(item)
In [33]:
item
Out[33]:
In [34]:
nomes = []
for nome in nomes:
print(nome)
else:
print("Nenhum nome")
In [35]:
nomes = ["fulano", "sicrano", "beltrano"]
for nome in nomes:
if nome in ["fulano", "beltrano"]:
print(nome)
else:
break
In [36]:
nomes = ["fulano", "sicrano", "beltrano"]
for nome in nomes:
if nome in ["fulano", "beltrano"]:
print(nome)
else:
continue
In [40]:
soma = 0
contador = 0
while contador < 5:
num = input("Número: ")
num = int(num)
if num > 10:
continue
soma = soma + num
contador = contador + 1
In [41]:
print(soma)
In [43]:
info = {"nome": "gileno", "email": "contato@gilenofilho.com.br"}
In [44]:
for chave in info:
print(chave)
In [45]:
info.items()
Out[45]:
In [47]:
for chave, valor in info.items():
print(chave, valor)
In [1]:
for i in range(10):
print(i)
In [2]:
numero = 10
print(numero % 2)
In [ ]: