Truthy & falsy
Në shqip përdoret i njëjti emër.
ShpjegimiSQ
Në Python dhe JavaScript çdo vlerë mund të përdoret në një if: disa vlera llogariten si „false“ (falsy) — 0, teksti bosh "", lista bosh, null/None — dhe të gjitha të tjerat si „true“ (truthy).
EnglishEN
In Python and JavaScript, any value can be used in an if: some values count as “false” (falsy) — 0, the empty string "", an empty list, null/None — and everything else counts as “true” (truthy).
Si ta mendosh
Si kur mamaja pyet „A ka qumësht në frigorifer?“: një shishe bosh llogaritet „jo“, edhe pse shishja është aty.
Lexoje në anglisht
Like Mum asking “Is there milk in the fridge?”: an empty bottle counts as “no”, even though the bottle is there.
Shembull kodipython
emri = ""
if not emri:
print("Shkruaj emrin!") # teksti bosh është falsy
if [1, 2]: print("Lista ka elemente") # truthy