PYTHON
PYTHON
com/courses/learn-python/lessons/python-syntax/exercises/name-
error
Erros no Python:
EXPLICAÇÃO DE PORCENTAGEM
valor1 = 50
total1 = 10
ZeroDivisionError
Quando um número é dividido por zero.
SyntaxError
Quando existe erro de operador, parênteses, aspas, etc.
NameError
Quando a variável é desconhecida.
Elif
Se a condição inicial não atender, ele verifica o próximo “if”, que é o Elif, caso o elif seja
verdadeiro, então não irá pro próximo. Somente no último, utilizar else.
pet_type = "fish"
if pet_type == "dog":
print("You have a dog.")
elif pet_type == "cat":
print("You have a cat.")
elif pet_type == "fish":
# this is performed
print("You have a fish")
else:
print("Not sure!")
Equal Operator ==
Boolean Values
Retorna o tipo de dado.
is_true = True
is_false = False
print(type(is_false))
not Operator
not True # Evaluates to False
not False # Evaluates to True
1 > 2 # Evaluates to False
not 1 > 2 # Evaluates to True
1 == 1 # Evaluates to True
not 1 == 1 # Evaluates to False
SyntaxError
age = 7 + 5 = 4
File "<stdin>", line 1
SyntaxError: can't assign to operator
Lists
primes = [2, 3, 5, 7, 11]
print(primes)
List Indices
Determina o que está naquela posição
berries = ["blueberry", "cranberry", "raspberry"]
berries[0] # "blueberry"
berries[2] # "raspberry"
print(berries[1])
Modifying 2D Lists
Para modificar o elemento de uma tabela, informa linha e a coluna:
# A 2D list of names and hobbies
class_name_hobbies = [["Jenny", "Breakdancing"], ["Alexus",
"Photography"], ["Grace", "Soccer"]]
# The sublist of Jenny is at index 0. The hobby is at index 1 of
the sublist.
class_name_hobbies[1][1] = "Meditation"
print(class_name_hobbies)
Caso queira mostrar somente uma linha.
print (class_name_hobbies [0])