Introducere în Python pentru dezvoltatori
Jasmin Ludolf
Senior Data Science Content Developer
# Boolean variable
the_truth = True
print(the_truth)
True
Operatori de comparație
Verifică dacă două valori sunt egale
==# Compare if 2 is equal to 3
2 == 3
False
# Check that 2 is not equal to 3
2 != 3
True
# Is 5 less than 7?
5 < 7
True
# Is 5 less than or equal to 7?
5 <= 7
True
# Is 5 greater than 7?
5 > 7
False
# Is 5 greater or equal to 7?
5 >= 7
False
# Is James greater than Brian
"James" > "Brian"
True
if este îndeplinită, se execută acțiunea, altfel se sare# Check pasta quantities required_quantity = 500 pasta_quantity = 200# Compare pasta quantities if pasta_quantity >= required_quantity
if este îndeplinită, se execută acțiunea, altfel se sare# Check pasta quantities required_quantity = 500 pasta_quantity = 200# Compare pasta quantities if pasta_quantity >= required_quantity:
if este îndeplinită, se execută acțiunea, altfel se sare# Check pasta quantities required_quantity = 500 pasta_quantity = 200# Compare pasta quantities if pasta_quantity >= required_quantity:print("You have enough pasta!")
# Check pasta quantities required_quantity = 500 pasta_quantity = 200# Compare pasta quantities if pasta_quantity >= required_quantity:print("You have enough pasta!") # This line is not indented
print("You have enough pasta!")
^
IndentationError: expected an indented block
# Check pasta quantities required_quantity = 500 pasta_quantity = 200# Compare pasta quantities if pasta_quantity >= required_quantity:print("You have enough pasta!")elif pasta_quantity >= 300: print("Nearly enough pasta. Try a smaller portion.")
elif!# Check pasta quantities required_quantity = 500 pasta_quantity = 200# Compare pasta quantities if pasta_quantity >= required_quantity:print("You have enough pasta!")elif pasta_quantity >= 300: print("Nearly enough pasta. Try a smaller portion.")# Otherwise... else: print("Not enough pasta.")
Not enough pasta.
| Operator | Funcție |
|---|---|
== |
Egal cu |
!= |
Diferit de |
> |
Mai mare decât |
>= |
Mai mare sau egal cu |
< |
Mai mic decât |
<= |
Mai mic sau egal cu |
| Cuvânt cheie | Funcție | Utilizare |
|---|---|---|
if |
Dacă condiția este îndeplinită | Primul în flux |
elif |
Altfel verifică condiția | După if |
else |
Altfel execută această acțiune | După elif |
Introducere în Python pentru dezvoltatori