Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

ตัวดำเนินการ 'not in' ใน Python ทำหน้าที่อะไร?

ใน Python in และ not in เรียกว่าตัวดำเนินการสมาชิก (membership operators) วัตถุประสงค์คือตรวจสอบว่าออบเจ็กต์เป็นสมาชิกของลำดับข้อมูล (sequence object) เช่น string, list, หรือ tuple ตัวดำเนินการ not in คืนค่า False หากออบเจ็กต์อยู่ในลำดับข้อมูล คืนค่า True หากไม่พบ

>> 'p' not in 'Tutorialspoint'
False
>>> 'c' not in 'Tutorialspoint'
True
>>> 10 not in range(0,5)
True