Issue
I just started Python two days ago and I came across 2 types of if
statements: one where is
was used and another where in
was used. So what is basically the difference between them?
Solution
The is keyword is used to test if two variables refer to the same object. Example:
x = ["apple", "banana", "cherry"]
y = x
print(x is y)
The in keyword is used to check if a value is present in a sequence (list, range, string etc.). Example:
fruits = ["apple", "banana", "cherry"]
if "banana" in fruits:
print("yes")
Those are not "part" of an IF statement per-se.
Answered By - OldProgrammer
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.