+ 1
in python 3 i don't understand This (in, not in, is, is not) please give me some examples also
1) in 2) not in 3) is 4) is not
3 odpowiedzi
+ 10
Not trying to be rude, but I don't think that you're going to learn anything if you keep asking other people to explain every feature of Python to you. Of course you can ask questions if there's something you didn't understand. But you already asked what "not" means. Now you're asking what "in" means and how "in" is different from "not in". If you tried to understand the explanations that everyone gave you about "not", there would be no need to ask how "in" is different from "not in".
+ 2
in & not in is an expressing used to test membership of something to a container such as lists, tuples, sets, dic, etc. or not, it should return either True or False.
For example,
>>> 2 in [1, 3, 5]
False
>>> 2 not in [1, 3, 5]
True
While is & is not test for an object's identity, i.e. to ask python if one object is the same as another object.
For example, if we identify that x = 10 and y = 20 then asked Python if x is y then the result is False. Similarly, you can check if x is not y and Python will return True.
I hope this helps :)
0
in and is are comparison operators.
Comparison operators can only return either True or False.
not is a logical operator.
Logical operators also can only return either True or False
Using not you would change True into False and False into True.
in can be used to search whether an item is in a iterable.
not in can be used to search whether an item is not in an iterable.
To understand is, you need to know a function id()
is can be used to check whether the id of 2 values is same.
is not can be used to check whether the id of 2 values is not same.