Trong bài viết này, chúng tôi sẽ học các nhà khai thác thành viên và nhận dạng Python.
Các nhà khai thác thành viên
Python cung cấp hai nhà khai thác thành viên để kiểm tra hoặc xác thực thành viên của một giá trị. Nó kiểm tra tư cách thành viên trong một chuỗi, chẳng hạn như chuỗi, danh sách hoặc bộ dữ liệu. & Nbsp;
Trong toán tử: Toán tử ’trong toán tử được sử dụng để kiểm tra xem một ký tự/ chuỗi con/ phần tử có tồn tại theo trình tự hay không. Đánh giá đúng nếu nó tìm thấy phần tử được chỉ định trong một chuỗi khác là sai. Ví dụ,The ‘in’ operator is used to check if a character/ substring/ element exists in a sequence or not. Evaluate to True if it finds the specified element in a sequence otherwise False. For example,
'G' in 'GeeksforGeeks' # Checking 'G' in String True 'g' in 'GeeksforGeeks' #Checking 'g' in string since Python is case-sensitive,returns False False 'Geeks' in ['Geeks', 'For','Geeks'] #Checking 'Geeks' in list of strings True 10 in [10000,1000,100,10] #Checking 10 in list of integers True dict1={1:'Geeks',2:'For',3:'Geeks'} # Checking 3 in keys of dictionary 3 in dict1 True
Python3
list1
=
[
1
,
not overlapping not overlapping not overlapping not overlapping not overlapping0____9____
not overlapping not overlapping not overlapping not overlapping not overlapping2
not overlapping not overlapping not overlapping not overlapping not overlapping8
=
[
x is NOT present in given list y is present in given list1
,
x is NOT present in given list y is present in given list3
,
x is NOT present in given list y is present in given list5
,
x is NOT present in given list y is present in given list7
not overlapping not overlapping not overlapping not overlapping not overlapping7
x is NOT present in given list y is present in given list9
True 140704586672032 1407045866720320
True 140704586672032 1407045866720321
True 140704586672032 1407045866720322
True 140704586672032 1407045866720323
True 140704586672032 1407045866720324
True 140704586672032 1407045866720320
True 140704586672032 1407045866720321
True 140704586672032 1407045866720327
True 140704586672032 1407045866720328
True 140704586672032 1407045866720329
Output: False True0
Output: False True1
Output: False True2
True 140704586672032 1407045866720323
Output: False True4
Output: False True5
True 140704586672032 1407045866720328
True 140704586672032 1407045866720329
Output: False True0
Output: False True9
Output: False True2
Đầu ra
not overlapping not overlapping not overlapping not overlapping not overlapping
Ví dụ tương tự mà không cần sử dụng trong toán tử:
Python3
list1
1 list1
2
True 140704586672032 1407045866720323
list1
4=
list1
6True 140704586672032 1407045866720323
list1
8=
list1
6True 140704586672032 1407045866720323
x is NOT present in given list y is present in given list9
=
3True 140704586672032 1407045866720321
True 140704586672032 1407045866720322
True 140704586672032 1407045866720328
list1
4=
8=
1
True 140704586672032 1407045866720323
x is NOT present in given list y is present in given list9
=
3True 140704586672032 1407045866720321
True 140704586672032 1407045866720327
True 140704586672032 1407045866720328
list1
8=
8=
1
True 140704586672032 1407045866720323
x is NOT present in given list y is present in given list9
=
3True 140704586672032 1407045866720321
1
5Output: False True0
list1
61
8True 140704586672032 1407045866720328
x is NOT present in given list y is present in given list9
,
1True 140704586672032 1407045866720321
1
5Output: False True0
list1
6,
6,
7
True 140704586672032 1407045866720324
,
9=
=
not overlapping not overlapping not overlapping not overlapping not overlapping02
not overlapping not overlapping not overlapping not overlapping not overlapping03
not overlapping not overlapping not overlapping not overlapping not overlapping04
1
True 140704586672032 1407045866720323
not overlapping not overlapping not overlapping not overlapping not overlapping04
list1
6list1
=
[
1
,
not overlapping not overlapping not overlapping not overlapping not overlapping0____9____
not overlapping not overlapping not overlapping not overlapping not overlapping2
not overlapping not overlapping not overlapping not overlapping not overlapping8
=
[
x is NOT present in given list y is present in given list1
,
x is NOT present in given list y is present in given list3
,
x is NOT present in given list y is present in given list5
,
x is NOT present in given list y is present in given list7
not overlapping not overlapping not overlapping not overlapping not overlapping7
True 140704586672032 1407045866720324
not overlapping not overlapping not overlapping not overlapping not overlapping34
x is NOT present in given list y is present in given list9
True 140704586672032 1407045866720320
True 140704586672032 1407045866720321
True 140704586672032 1407045866720322
Output: False True4
Output: False True5
True 140704586672032 1407045866720323
True 140704586672032 1407045866720329
Output: False True0
Output: False True9
Output: False True2
True
140704586672032
140704586672032
3True
140704586672032
140704586672032
4 True
140704586672032
140704586672032
0True
140704586672032
140704586672032
1 True
140704586672032
140704586672032
7 Evaluates to true if it does not finds a variable in the specified sequence and false otherwise.
Python3
True 140704586672032 1407045866720328
True 140704586672032 1407045866720329
Output: False True0
Output: False True9
Output: False True2
Đầu ra
Ví dụ tương tự mà không cần sử dụng trong toán tử:
list1
1 list1
2
True 140704586672032 1407045866720323
True 140704586672032 1407045866720329
Output: False True0
not overlapping not overlapping not overlapping not overlapping not overlapping75
Output: False True2
Output: False True4
Output: False True5
True 140704586672032 1407045866720323
True 140704586672032 1407045866720329
Output: False True0
not overlapping not overlapping not overlapping not overlapping not overlapping82
Output: False True2
True 140704586672032 1407045866720323
list1
4=
list1
6True 140704586672032 1407045866720323
True 140704586672032 1407045866720329
Output: False True0
not overlapping not overlapping not overlapping not overlapping not overlapping92
Output: False True2
Output: False True4
Output: False True5
True 140704586672032 1407045866720323
True 140704586672032 1407045866720329
Output: False True0
not overlapping not overlapping not overlapping not overlapping not overlapping99
Output: False True2
Output:
x is NOT present in given list y is present in given list
True
140704586672032
140704586672032
3list1
8=
list1
6
True 140704586672032 1407045866720323
x is NOT present in given list y is present in given list9
=
3True 140704586672032 1407045866720321
True 140704586672032 1407045866720322
There are different identity operators such as
True
140704586672032
140704586672032
8list1
4=
8=
1
Evaluates to True if the variables on either side of the operator point to the same object and false otherwise.
Python3
True 140704586672032 1407045866720323
x is NOT present in given list y is present in given list9
=
3True 140704586672032 1407045866720321
True 140704586672032 1407045866720327
True 140704586672032 1407045866720328
list1
8=
8=
1
True 140704586672032 1407045866720323
x is NOT present in given list y is present in given list9
=
3True 140704586672032 1407045866720321
1
5Output: False True0
list1
61
8x is NOT present in given list y is present in given list11
x is NOT present in given list y is present in given list12
x is NOT present in given list y is present in given list11
x is NOT present in given list y is present in given list14
True 140704586672032 140704586672032
True 140704586672032 1407045866720328
x is NOT present in given list y is present in given list9
,
1True 140704586672032 1407045866720321
1
5Output: False True0
list1
6,
6,
7True
140704586672032
140704586672032
4,
9=
=
not overlapping
not overlapping
not overlapping
not overlapping
not overlapping
02 Evaluates to true if the variables on either side of the operator point to a different object and true otherwise.
Python3
True 140704586672032 1407045866720323
x is NOT present in given list y is present in given list9
=
3True 140704586672032 1407045866720321
True 140704586672032 1407045866720327
True 140704586672032 1407045866720328
list1
8=
8=
1
True 140704586672032 1407045866720323
x is NOT present in given list y is present in given list9
=
3True 140704586672032 1407045866720321
1
5Output: False True0
list1
61
8Output: False True4
Output: False True5
True 140704586672032 1407045866720323
True 140704586672032 1407045866720329
Output: False True0
x is NOT present in given list y is present in given list36
Output: False True2
True 140704586672032 1407045866720328
x is NOT present in given list y is present in given list9
,
1True 140704586672032 1407045866720321
1
5Output: False True0
list1
6,
6True 140704586672032 1407045866720328
list1
8=
8=
1
True 140704586672032 1407045866720323
True 140704586672032 1407045866720329
Output: False True0
x is NOT present in given list y is present in given list29
Output: False True2
Output: False True4
Output: False True5
True 140704586672032 1407045866720323
True 140704586672032 1407045866720329
Output: False True0
x is NOT present in given list y is present in given list36
Output: False True2
Output: False True