xin chào. Vì vậy, hôm nay chúng ta sẽ thảo luận về các nhà điều hành của người Viking và không phải trong các nhà khai thác ở Python. toán tử “in” và “not in” trong Python
Nội dung chính Hiển thị
Python "trong nhà điều hành"
Về cơ bản, toán tử
#not in operator working list1= [1,2,3,4,5] string1= "My name is AskPython" tuple1=[11,22,33,44] print[5 not in list1] #False print["is" not in string1] #False print[88 not in tuple1] #True7 trong Python có kiểm tra xem giá trị được xác định chỉ có phải là phần cấu trúc thành phần tử của chuỗi như chuỗi, mảng, danh sách hoặc bộ, v. v
Khi được sử dụng trong một điều kiện, câu lệnh trả về kết quả boolean đánh giá thành
#not in operator working list1= [1,2,3,4,5] string1= "My name is AskPython" tuple1=[11,22,33,44] print[5 not in list1] #False print["is" not in string1] #False print[88 not in tuple1] #True8 hoặc
#not in operator working list1= [1,2,3,4,5] string1= "My name is AskPython" tuple1=[11,22,33,44] print[5 not in list1] #False print["is" not in string1] #False print[88 not in tuple1] #True9. Khi giá trị được định giá chỉ được tìm thấy bên trong chuỗi, câu lệnh trả về
#not in operator working list1= [1,2,3,4,5] string1= "My name is AskPython" tuple1=[11,22,33,44] print[5 not in list1] #False print["is" not in string1] #False print[88 not in tuple1] #True8. Trong khi đó khi nó không được tìm thấy, chúng ta sẽ nhận được một
#not in operator working list1= [1,2,3,4,5] string1= "My name is AskPython" tuple1=[11,22,33,44] print[5 not in list1] #False print["is" not in string1] #False print[88 not in tuple1] #True9. được tìm thấy bên trong chuỗi, câu lệnh trả về
#not in operator working list1= [1,2,3,4,5] string1= "My name is AskPython" tuple1=[11,22,33,44] print[5 not in list1] #False print["is" not in string1] #False print[88 not in tuple1] #True8. Trong khi không tìm thấy nó, chúng tôi nhận được một
#not in operator working list1= [1,2,3,4,5] string1= "My name is AskPython" tuple1=[11,22,33,44] print[5 not in list1] #False print["is" not in string1] #False print[88 not in tuple1] #True9
Không cho phép chúng tôi lấy một ví dụ để hiểu rõ hơn về nhà điều hành
#not in operator working list1= [1,2,3,4,5] string1= "My name is AskPython" tuple1=[11,22,33,44] print[5 not in list1] #False print["is" not in string1] #False print[88 not in tuple1] #True7 đang làm việc________số 8
đầu ra
Đây
Đầu tiên, chúng tôi đã khởi tạo một danh sách
#not in operator working list1= [1,2,3,4,5] string1= "My name is AskPython" tuple1=[11,22,33,44] print[5 not in list1] #False print["is" not in string1] #False print[88 not in tuple1] #True5, chuỗi ____10 và một tuple
#not in operator working list1= [1,2,3,4,5] string1= "My name is AskPython" tuple1=[11,22,33,44] print[5 not in list1] #False print["is" not in string1] #False print[88 not in tuple1] #True1 with a value value. Sau đó, chúng tôi sử dụng toán tử
#not in operator working list1= [1,2,3,4,5] string1= "My name is AskPython" tuple1=[11,22,33,44] print[5 not in list1] #False print["is" not in string1] #False print[88 not in tuple1] #True7 để kiểm tra xem một số giá trị có phải là một phần của chuỗi trên hay không
Như chúng ta có thể thấy từ đầu ra ở trên,
#not in operator working list1= [1,2,3,4,5] string1= "My name is AskPython" tuple1=[11,22,33,44] print[5 not in list1] #False print["is" not in string1] #False print[88 not in tuple1] #True3 đánh giá thành sự thật. Trong đó biểu thị rằng giá trị 5 được tìm thấy bên trong danh sách. Thật. Điều đó có nghĩa là giá trị 5 được tìm thấy trong danh sách
Tương tự, sử dụng toán tử
#not in operator working list1= [1,2,3,4,5] string1= "My name is AskPython" tuple1=[11,22,33,44] print[5 not in list1] #False print["is" not in string1] #False print[88 not in tuple1] #True7, chúng tôi cũng xác nhận sự hiện diện của chuỗi là IS IS trong ____10. Nhưng đối với trường hợp cuối cùng, điều kiện dẫn đến sai vì 88 không có trong chuỗi
#not in operator working list1= [1,2,3,4,5] string1= "My name is AskPython" tuple1=[11,22,33,44] print[5 not in list1] #False print["is" not in string1] #False print[88 not in tuple1] #True1. “là” trong
#not in operator working list1= [1,2,3,4,5] string1= "My name is AskPython" tuple1=[11,22,33,44] print[5 not in list1] #False print["is" not in string1] #False print[88 not in tuple1] #True0. Nhưng đối với trường hợp cuối cùng, điều kiện dẫn đến Sai vì 88 không có trong dãy
#not in operator working list1= [1,2,3,4,5] string1= "My name is AskPython" tuple1=[11,22,33,44] print[5 not in list1] #False print["is" not in string1] #False print[88 not in tuple1] #True1
Python "không có trong nhà điều hành"
Toán tử
#not in operator working list1= [1,2,3,4,5] string1= "My name is AskPython" tuple1=[11,22,33,44] print[5 not in list1] #False print["is" not in string1] #False print[88 not in tuple1] #True7 trong Python hoạt động chính xác theo cách đảo ngược khi toán tử
#not in operator working list1= [1,2,3,4,5] string1= "My name is AskPython" tuple1=[11,22,33,44] print[5 not in list1] #False print["is" not in string1] #False print[88 not in tuple1] #True7 hoạt động. Nó kiểm tra sự hiện diện của một giá trị chỉ được định sẵn bên trong một chuỗi định nghĩa nhất nhưng các giá trị được trả lại của nó hoàn toàn ngược lại với toán tử
#not in operator working list1= [1,2,3,4,5] string1= "My name is AskPython" tuple1=[11,22,33,44] print[5 not in list1] #False print["is" not in string1] #False print[88 not in tuple1] #True7
Khi được sử dụng trong một điều kiện với giá trị chỉ được định sẵn bên trong chuỗi, câu lệnh trả về
#not in operator working list1= [1,2,3,4,5] string1= "My name is AskPython" tuple1=[11,22,33,44] print[5 not in list1] #False print["is" not in string1] #False print[88 not in tuple1] #True9. Trong khi đó khi không, chúng ta sẽ nhận được
#not in operator working list1= [1,2,3,4,5] string1= "My name is AskPython" tuple1=[11,22,33,44] print[5 not in list1] #False print["is" not in string1] #False print[88 not in tuple1] #True8
Chúng ta hãy lấy ví dụ trước, chỉ cần thay thế toán tử
#not in operator working list1= [1,2,3,4,5] string1= "My name is AskPython" tuple1=[11,22,33,44] print[5 not in list1] #False print["is" not in string1] #False print[88 not in tuple1] #True7 bằng
#not in operator working list1= [1,2,3,4,5] string1= "My name is AskPython" tuple1=[11,22,33,44] print[5 not in list1] #False print["is" not in string1] #False print[88 not in tuple1] #True7.
#not in operator working list1= [1,2,3,4,5] string1= "My name is AskPython" tuple1=[11,22,33,44] print[5 not in list1] #False print["is" not in string1] #False print[88 not in tuple1] #True
đầu ra
not in the head
Đúng như dự đoán, đầu ra kết quả hoàn toàn trái ngược với những gì chúng ta nhận được trước đó bằng cách sử dụng toán tử
#not in operator working list1= [1,2,3,4,5] string1= "My name is AskPython" tuple1=[11,22,33,44] print[5 not in list1] #False print["is" not in string1] #False print[88 not in tuple1] #True7. ngược lại với những gì chúng tôi đã nhận được trước đó bằng cách sử dụng toán tử
#not in operator working list1= [1,2,3,4,5] string1= "My name is AskPython" tuple1=[11,22,33,44] print[5 not in list1] #False print["is" not in string1] #False print[88 not in tuple1] #True7
Công việc của người Viking trong các nhà điều hành của người Viking và không phải trong các nhà khai thác trong từ điển Python
Trước đây chúng tôi đã thảo luận về hoạt động của toán tử
#not in operator working list1= [1,2,3,4,5] string1= "My name is AskPython" tuple1=[11,22,33,44] print[5 not in list1] #False print["is" not in string1] #False print[88 not in tuple1] #True7 và
#not in operator working list1= [1,2,3,4,5] string1= "My name is AskPython" tuple1=[11,22,33,44] print[5 not in list1] #False print["is" not in string1] #False print[88 not in tuple1] #True7 trên các loại trình tự khác nhau. Nhưng từ điển không phải là trình tự. Không giống như chúng, từ điển được thiết lập chỉ mục trên cơ sở từ khóa. phím
Vì sao các lệnh khai thác trong làm việc trên từ điển?
Hãy để tôi cố gắng hiểu một ví dụ
#not in operator working list1= [1,2,3,4,5] string1= "My name is AskPython" tuple1=[11,22,33,44] print[5 not in list1] #False print["is" not in string1] #False print[88 not in tuple1] #True0
đầu ra
Use in and not have in dictionary
Trước đó, tôi đã khởi tạo một từ điển
#not in operator working list1= [1,2,3,4,5] string1= "My name is AskPython" tuple1=[11,22,33,44] print[5 not in list1] #False print["is" not in string1] #False print[88 not in tuple1] #True07 with a number of key and the value in the most fixed. khóa và giá trị tương ứng
Như chúng ta có thể thấy từ đầu ra ở trên,
#not in operator working list1= [1,2,3,4,5] string1= "My name is AskPython" tuple1=[11,22,33,44] print[5 not in list1] #False print["is" not in string1] #False print[88 not in tuple1] #True08 đánh giá thành sai. Trong khi đó,
#not in operator working list1= [1,2,3,4,5] string1= "My name is AskPython" tuple1=[11,22,33,44] print[5 not in list1] #False print["is" not in string1] #False print[88 not in tuple1] #True09 cho chúng ta sự thật. Sai. Trong khi đó, ______ 009 cho chúng ta sự thật
Vì vậy, rõ ràng là toán tử trong tìm kiếm phần tử giữa các từ điển từ khóa chứ không phải các giá trị. Do đó, tương tự như câu lệnh cuối cùng
#not in operator working list1= [1,2,3,4,5] string1= "My name is AskPython" tuple1=[11,22,33,44] print[5 not in list1] #False print["is" not in string1] #False print[88 not in tuple1] #True70 cũng dẫn đến sai vì nó không phải là chìa khóa trong từ điển. khóa chứ không phải giá trị. Do đó, tương tự, câu lệnh cuối cùng
#not in operator working list1= [1,2,3,4,5] string1= "My name is AskPython" tuple1=[11,22,33,44] print[5 not in list1] #False print["is" not in string1] #False print[88 not in tuple1] #True70 cũng dẫn đến Sai vì nó không phải là khóa trong từ điển