is keyword in Python

In programming, a keyword is a “reserved word” by the language which conveys special meaning to the interpreter. It may be a command or a parameter. Keywords cannot be used as a variable name in the program snippet. Python language also reserves some of the keywords that convey special meaning. In Python, keywords are case sensitive.

is keyword

This keyword is used to test object identity. The “is keyword” is used to test whether two variables belong to the same object. The test will return True if the two objects are the same else it will return False even if the two objects are 100% equal.

Note: The == operator is used to test if two objects are the same.



Syntax:

a is b

# Using if statement
if a is b:
    statement(s)

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python program to demonstrate
# is keyword
  
  
x = ["a", "b", "c", "d"]
  
y =  ["a", "b", "c", "d"]
  
print(x is y)
print(x == y)

chevron_right


Output :
False
True

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python program to demonstrate
# is keyword
  
  
x = 10
y = 10
  
if x is y:
    print(True)
else:
    print(False)

chevron_right


Output:

True
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.