This may or may not be counter-intuitive. If it is, here is the simple explanation I like:
For a non-empty iterable X, you can consider all(X) to be equivalent to X[0] and all(X[1:])
When you expand everything, you get X[0] and X[1] and ... and all([]), notice how things will collapse if all([]) return False, because if it is the case, all() will never return True.
In the same way, you can consider any(X) to be equivalent to X[0] or any(X[1:])
When you expand everything, you get X[0] or X[1] or ... or any([]), notice how things will collapse if any([]) return True, because if it is the case, any() will never return False.
This is neither a good nor correct explanation, because one can argue that they can define all() and any() operator with a non-empty iterable as the base of its recursive cause. I am not even sure if a set with negative numbers of elements is a thing, which will spark even more debate.
เห็นโพสต์นึงในอินเทอร์เน็ตพูดถึงการใช้ตัวดำเนินการ == และ is ในไพทอนแล้วน่าจะมีเนื้อหาที่ไม่ค่อยถูกนัก
มิตรสหายเนยสดท่านหนึ่ง ใจดีไปแก้ไขที่ต้นทางให้ (link open in new tab) มองว่าผู้เขียนน่าจะรู้สึกเหมือน is เป็น === ใน JS กล่าวคือเป็น type strict comparison ซึ่งไม่ใช่ในกรณีของไพทอนอย่างแน่นอน เพราะตัวภาษาเองเป็น strict typed อยู่แล้ว
เลยแวบมาเขียนอะไรขำๆ สักเล็กน้อย เกี่ยวกับการใช้ == และ is สักหน่อยแล้วกัน
Prerequisites
ก่อนอื่นต้องเข้าใจว่า == มีไว้เช็กความค่าเท่ากัน และ is มีไว้เช็กว่า object สองตัวเป็น instance เดียวกันไหม
>>> a = []
>>> b = []
>>> a == b
True
>>> a is b
False
The current implementation keeps an array of integer objects for all integers between -5 and 256. When you create an int in that range you actually just get back a reference to the existing object.
These are how one should* not create an alumni association:
Create a chat group.
Establish themselves as “seniors”.
Mandate, Suggest that the calls emphasising seniority be used, therefore creating an environment that does not reflect the dynamics and the relationships between alumnus in an inclusive and up-to-date manner.
Make the aforementioned chat group becomes forward from grandmas group.
* Despite the fact that ones should not, ones might actually do them.
ส่วนหนึ่งมองว่าหากอยากจะเข้าใจตลาดล่าง ต้องเริ่มจากการพยายามทำความเข้าใจพฤติกรรมและขั้นตอนวิธีในการ “เหยียด” ของ elite หรือ upper-middle class ที่มองลงมายัง middle class ทั่วไปก่อน
ถ้า middle class ไม่ได้ naive ขนาดนั้นสักเท่าไหร่ก็คงพอรู้ว่าการเหยียดแบบนี้มีจริง และเราคิดว่า middle class บางกลุ่มแสดงออกผ่านการรีเฟลกซ์กลับไปที่ชนชั้นที่ต่ำกว่าตามลำดับ