Expression boolean di python - Python tutorial
>>> 5 == 5
True
>>> 5 == 6
False
True
>>> 5 == 6
False
Benar atau salah adalah salah satu nilai spesial yang termasuk ke type bool, bukan termasuk string.
>>> type(True)
<type 'bool'>
>>> type(False)
<type 'bool'>
<type 'bool'>
>>> type(False)
<type 'bool'>
Operator ini == adalah salahsatu operator pembanding seperti contoh ini:
x != y # x is not equal to y
x > y # x is greater than y
x < y # x is less than y
x >= y # x is greater than or equal to y
x <= y # x is less than or equal to y
x is y # x is the same as y
x is not y # x is not the same as y
x > y # x is greater than y
x < y # x is less than y
x >= y # x is greater than or equal to y
x <= y # x is less than or equal to y
x is y # x is the same as y
x is not y # x is not the same as y
Walaupun operasi ini mungkin familiar dengan anda, simbol python adalah berbeda dengan simbol matematika untuk operasi yang sama. Salah satu kesalahan yang umum adalah menggunakan tanda (=) bukan menggunakan tanda (==). Harap diingat bahwa tanda = menunjukkan pemetaan ke variabel sedangkan tanda == merupakan operator pembanding.
Komentar
Posting Komentar