Python

is vs ==

Në shqip: Dallimi mes is dhe ==

ShpjegimiSQ

== kontrollon nëse dy vlera janë të njëjta, ndërsa is kontrollon nëse janë fiks i njëjti objekt në memorie. Për krahasime normale përdor ==; is përdore kryesisht me None: if x is None.

EnglishEN

== checks whether two values are equal, while is checks whether they are exactly the same object in memory. For normal comparisons use ==; use is mainly with None: if x is None.

Si ta mendosh

Dy fanella identike të Kosovës janë == (duken njësoj), por vetëm fanella jote është is fanella jote.

Lexoje në anglisht

Two identical Kosovo shirts are == (they look the same), but only your shirt is your shirt.

Shembull kodipython

a = [1, 2]
b = [1, 2]
print(a == b)  # True  — njëjta vlerë
print(a is b)  # False — objekte të ndryshme

Terma të lidhur